How to Save Player Data in Roblox With DataStores
Saving player progress is one of the first real challenges in Roblox development. Here is how DataStores work and how to use them without losing data.
Almost every real Roblox game needs to remember player progress: coins, levels, items. That is what DataStores are for. They are powerful but easy to get wrong, so here is how to use them safely.
What a DataStore is
A DataStore is Roblox key-value storage that persists between sessions. You access it through DataStoreService, get a store by name, and read or write values keyed by the player user ID.
The basic pattern
- Get the store once with
DataStoreService:GetDataStore("name"). - When a player joins, load their data with
GetAsync(key). - When a player leaves, save their data with
SetAsync(key, value).
Always wrap calls in pcall
DataStore calls talk to Roblox servers and can fail. If you do not handle errors, a failed call can crash your save logic and lose data. Wrap every read and write in pcall and handle the failure case.
Save on leave and on shutdown
Save when a player leaves (PlayerRemoving), and also use game:BindToClose to save everyone when the server shuts down. Without BindToClose, players in the last moments before a restart can lose progress.
Avoid data loss traps
- Do not save every second. DataStores have request limits; batch your saves.
- Consider session locking. If the same player joins two servers, saves can overwrite each other. Session locking prevents this.
- Validate loaded data. Handle the case where a player has no saved data yet (first join).
The takeaway
Load on join, save on leave and shutdown, wrap everything in pcall, and respect the request limits. Get that right and player progress stays safe.
If you would rather not build a robust data system from scratch, ready-made data and save systems are available on ModForge, tested and documented so you skip the common pitfalls.