Log in
Login Sign up Blog Tools

DataStore Explained: How Saving Player Data Works in Roblox Games

DataStore is the invisible system behind every saved coin, level and inventory in Roblox games. Here is how it works, a complete save/load example for leaderstats, and the mistakes that wipe player data.

DataStore Explained: How Saving Player Data Works in Roblox Games
In this guide What DataStore Actually Is When Saving Must Happen GetAsync, SetAsync and UpdateAsync in Plain Language A Complete leaderstats Save/Load Example Why Players Actually Lose Data Testing in Studio: The Setting Everyone Forgets Limits and Throttling, Without the Mathematics Headache Frequently Asked Questions Why does my data save in the real game but not when I test in Studio? Do I need DataStore for a game with no saving, like a simple obby with no coins? What happens to saved data if I rename my DataStore, for example from "Coins_v1" to "Coins_v2"? Related Guides on RBXMods Sources

Almost every question in a Roblox developer forum eventually becomes the same question: "Why did my player's coins reset?" The system behind saving is called DataStore, and it is not difficult once somebody explains what it actually is, instead of just handing you a script to copy. This guide explains DataStore in plain language, shows a complete working save and load example for the classic leaderstats setup, and covers the boring details, like request limits and a Studio setting almost everyone forgets, that decide whether your players keep their progress or lose it.

Key takeaways

  • A DataStore is a cloud key-value store on Roblox's servers, shared across every server of your experience — your script must ask for every save; nothing saves automatically.
  • Save on PlayerRemoving, BindToClose, and a staggered autosave timer — leave-saving alone loses progress whenever a server shuts down or crashes.
  • Use UpdateAsync when an old copy of the data might exist; blind SetAsync overwrites let a stale server erase newer progress.
  • Wrap every request in pcall and never save data you failed to load — a failed load followed by a leave-save is the classic way real player data gets overwritten with zeros.

What DataStore Actually Is

A DataStore is a storage box that lives on Roblox's servers, not inside your place file and not on the player's computer. Your game script asks Roblox to store a piece of data under a key (a unique name), and later asks for it back using the same key. For player data, the key is almost always built from the player's UserId, for example "Player_4829103", because a UserId never changes, while a username can.

Two rules follow from this design. First, data belongs to the experience, not to one server: a player can join any server of your game, anywhere in the world, and load the same saved coins. Second, your script is responsible for everything. Roblox will not save anything automatically. If your script never asks, nothing is stored, and when the player leaves, whatever was only in the server's memory disappears forever. Almost every "data loss" bug is some version of the script not asking at the right moment, or asking and failing without anyone noticing.

Illustration of a cloud storage vault with labelled boxes and coins flowing into it from a game character

When Saving Must Happen

You cannot save "at the end" in the way beginners imagine, because there is no neat end screen for a Roblox session. Saving happens in response to events:

  • PlayerRemoving fires when a player leaves the game. This is the main save moment. When it fires, your script should immediately collect that player's data and store it.
  • BindToClose is for the case where the whole server shuts down, for example when you close all servers for an update or a server is terminated. BindToClose gives your function a short window (about 30 seconds) to finish before the server dies. Without it, everyone online during a shutdown can lose everything since their last save. With many players online, save them in parallel and wait for the saves to finish, rather than saving one by one and risking the window running out.
  • Autosave on a timer is the safety net most real games add: save everyone every few minutes (commonly every 3–5 minutes, staggered so all players are not saved in the same second). If a server crashes without warning, players then lose minutes of progress instead of hours.

GetAsync, SetAsync and UpdateAsync in Plain Language

FunctionWhat it doesUse it for
GetAsync(key)Reads the saved value for a key and gives it back to your script. Returns nothing (nil) if the player has never saved.Loading a player's data when they join.
SetAsync(key, value)Writes a value, completely replacing whatever was there before, whether your script has seen the old value or not.First-time saves, or data where only one server could ever be writing.
UpdateAsync(key, function)Reads the current saved value, hands it to your function, and stores whatever your function returns, as one operation.Adding coins or items safely when an old copy of the data might exist, because the change is calculated from the newest saved value, not a stale one.

The SetAsync versus UpdateAsync difference matters in one specific trap: the same player somehow being active in two places at once, or an old server writing after a newer one. SetAsync blindly overwrites, so the stale server's older data wins and recent progress vanishes. UpdateAsync at least builds on the value that is actually stored. For simple single-place games, a careful SetAsync pattern works; the moment your game has multiple places or trading, UpdateAsync and stricter design become important.

A Complete leaderstats Save/Load Example

This is the smallest honest version of the pattern used by thousands of games. It creates a Coins leaderstat, loads the saved amount when a player joins, and saves when they leave and when the server closes. Put it in a normal Script in ServerScriptService, not a LocalScript; DataStore can only be reached from the server. If you are new to scripting itself, read our first Lua script guide before adapting this one. Note that the example below deliberately leaves the autosave timer out to stay readable — add a separate timed loop that calls the same save function every few minutes, staggered per player, as described above.

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local coinsStore = DataStoreService:GetDataStore("Coins_v1")

local function onPlayerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 0
	coins.Parent = leaderstats
	leaderstats.Parent = player

	local success, saved = pcall(function()
		return coinsStore:GetAsync("Player_" .. player.UserId)
	end)
	if success and saved ~= nil then
		coins.Value = saved
	end
end

local function savePlayer(player)
	local coins = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Coins")
	if not coins then return end
	local success, err = pcall(function()
		coinsStore:SetAsync("Player_" .. player.UserId, coins.Value)
	end)
	if not success then
		warn("Save failed for " .. player.Name .. ": " .. tostring(err))
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(savePlayer)
game:BindToClose(function()
	for _, player in ipairs(Players:GetPlayers()) do
		savePlayer(player)
	end
end)

Three details in this script are doing more work than they look like. The pcall wrappers mean a failed DataStore request shows a warning instead of breaking the whole script; an unprotected failed load can leave a player with a fresh 0 that later gets saved over their real data, which is the worst bug in this whole topic. The store name "Coins_v1" has a version baked into it, because changing the name is the clean way to start fresh data after you change your data format. And for anything beyond one number, real games save a table (coins, level, inventory together) under one key, because tables count as one request while separate stores for every stat burn through the limits described below.

Illustration of a save cycle with a character leaving a game and coins flowing to a cloud safe beside a clock

Why Players Actually Lose Data

  • Saving a failed load. The load request errors, the script continues with default values, and the leave-save overwrites the real data with defaults. Always check that the load succeeded before allowing a save.
  • No BindToClose. The developer updates the game, all servers shut down, and nobody's leave event gets a chance to finish, or it fires while requests are already failing.
  • Editing live data from Studio. With Studio API access enabled (next section), pressing Play in Studio can load and save against the real live data. One careless test with a test account is harmless; testing while impersonating real values is not.
  • Hitting request limits. If saves are being rejected for throttling, they simply do not happen, and unless you log failures, you find out from angry players.
  • Two sessions writing the same key. A player rapidly rejoining, or being in two connected places at once, can produce an older write landing after a newer one. This is often called the session-locking problem: standard DataStores do not lock a key to one session for you, so your design (single-writer rules, UpdateAsync, checking timestamps inside the saved table) has to prevent stale overwrites.

Testing in Studio: The Setting Everyone Forgets

By default, Studio cannot reach your game's live DataStores, and your load test will silently return nothing. The fix is Home > Game Settings > Security > Enable Studio Access to API Services, switched on, then publish the game once — the setting only takes effect for a published experience. Two warnings. First, after enabling it, Studio reads and writes real player data for your published game, so test with your own account. Second, Studio has a habit of making beginners think saving is broken when actually the game was never published after flipping the setting, publishing is what applies it. For the publish step itself, see our guide to publishing your game.

Limits and Throttling, Without the Mathematics Headache

Roblox limits how many DataStore requests an experience can make, because the service is shared. The practical facts you need are these, as shown on the official DataStore limits page (checked 4 Nov 2026; limits change, so check that page before designing around exact numbers). By default, budgets are per server and scale with the players in that server: for a standard DataStore, reads run at 60 + players × 40 requests per minute and writes at 60 + players × 40 per minute. Where experience-level budgets are enabled instead, reads run at 300 + concurrent users × 40 per minute and writes at 300 + concurrent users × 20 per minute. You can check the budget your server actually has in code with DataStoreService:GetRequestBudgetForRequestType().

Per key, the limits are different: a single key can be written at up to 4 MB per minute, with up to 1,024 calls per minute per key, and each request queue holds 30 requests — past that, requests fail with throttling errors in the 301–306 range. A saved value can be up to 4 MB (4,194,304 bytes) per key, which is far more than a normal player profile needs. Total storage for an experience is 500 MB plus 1 MB per lifetime user, counting only the latest version of each key, with version history kept for 30 days. When you exceed a budget, requests start failing with throttling errors, which is why the pattern in this guide saves on join, on leave, and on a spaced-out timer, rather than every time a coin changes. Saving on every change is the number-one design mistake in beginner games: it wastes the budget, risks throttling at the busiest moments, and saves nothing extra that a leave-save would not have covered.

Keep those rules, wrap every request in pcall, never save data you failed to load, and your players will keep their coins. That is genuinely most of DataStore mastery; everything else is optimisation.

Frequently Asked Questions

Why does my data save in the real game but not when I test in Studio?

Studio cannot use DataStores until you turn on "Enable Studio Access to API Services" in Home > Game Settings > Security and publish the game. Also remember that testing in Studio then touches your live data, so test on your own account, not with values copied from a real player.

Do I need DataStore for a game with no saving, like a simple obby with no coins?

No. If nothing needs to survive after a player leaves, you do not need DataStore at all. The moment you add anything players expect to keep, wins, coins, unlocked levels, items, you need it, and it is far easier to add at the start than to retrofit after players already have progress stored in their heads but nowhere else.

What happens to saved data if I rename my DataStore, for example from "Coins_v1" to "Coins_v2"?

The new name is a completely separate, empty storage box. Every player starts from nothing under the new key, and the old data still exists under the old name but is never read again. Developers use this deliberately to reset data after a big format change, and beginners do it accidentally by "tidying up" a name, so treat store names as permanent once your game has real players.

One last rule that covers almost every data-loss story in this guide: if a save can fail silently, assume it will, and make the failure loud — log it, warn on it, and never let a default value overwrite a real one.

Related Guides on RBXMods

RBXMods is not affiliated with or endorsed by Roblox Corporation. Roblox and the Roblox logo are trademarks of Roblox Corporation.

Sources

Pawan Nagare
Written by

Pawan Nagare

I'm Pawan Nagare, and I run RBXMods. I write practical Roblox guides about how games are actually made — Roblox Studio, scripting, publishing and growing a game — along with clear fixes for the errors and confusing changes players run into.

Every guide here is researched against official Roblox documentation and checked against the current version of Roblox before it is published — and I update posts when Roblox changes the rules.

My aim is simple: honest, up-to-date help that respects your time — no recycled lists, and no shortcuts that put your account at risk.