How to save player data in Roblox Studio with DataStores

Updated 17 November 2026 · By ClipClip

The short answer

A data store keeps a player's coins, stage or items between visits. Publish your game, turn on Enable Studio Access to API Services, and put the saving script below in ServerScriptService: it loads each player's leaderboard when they join and saves it when they leave, every 2 minutes and when the server closes. We tested it, and the mistakes that stop data from saving, in Roblox Studio on 17 November 2026.

Turn on Studio access

  1. Publish the game from Studio's File menu. A private game is enough.
  2. Open File, Experience Settings, then Security.
  3. Turn on Enable Studio Access to API Services and click Save.

Studio then uses the game's real data. For a game people already play, Roblox advises testing on a copy, so your tests never save over theirs.

The saving script

First a leaderboard, if your game has none: the values on it are what gets saved.

Script in ServerScriptService: the leaderboard
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	-- reuses the leaderboard if another script made it
	local leaderstats = player:FindFirstChild("leaderstats") or Instance.new("Folder")
	leaderstats.Name = "leaderstats" -- this exact name shows it on the leaderboard
	leaderstats.Parent = player

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 0
	coins.Parent = leaderstats
end)

Then the saving script:

Script in ServerScriptService: saving
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local store = DataStoreService:GetDataStore("PlayerData")
local loaded = {}
local saving = 0 -- saves still running

local function load(player)
	player:SetAttribute("Loaded", false) -- the other scripts wait for this
	local leaderstats = player:WaitForChild("leaderstats")

	local ok, saved
	for attempt = 1, 3 do
		ok, saved = pcall(store.GetAsync, store, "Player_" .. player.UserId)
		if ok then
			break
		end
		task.wait(2)
	end
	if not ok then
		-- never let anyone play, and save, with empty data
		warn("Couldn't load " .. player.Name .. ": " .. tostring(saved))
		player:Kick("Your data didn't load. Please rejoin.")
		return
	end

	for name, value in saved or {} do
		local stat = leaderstats:WaitForChild(name, 5)
		if stat then
			stat.Value = value
		end
	end
	if player.Parent then
		loaded[player] = true
		player:SetAttribute("Loaded", true)
	end
end

local function save(player)
	if not loaded[player] then
		return false
	end
	saving += 1
	local data = {}
	for _, stat in player.leaderstats:GetChildren() do
		if stat:IsA("ValueBase") then
			data[stat.Name] = stat.Value
		end
	end
	local ok, err = pcall(store.SetAsync, store, "Player_" .. player.UserId, data)
	if not ok then
		warn("Couldn't save " .. player.Name .. ": " .. tostring(err))
	end
	saving -= 1
	return ok
end

-- lets other scripts save a player at once, like after a purchase
local savePlayerData = Instance.new("BindableFunction")
savePlayerData.Name = "SavePlayerData"
savePlayerData.OnInvoke = save
savePlayerData.Parent = ServerScriptService

Players.PlayerAdded:Connect(load)
Players.PlayerRemoving:Connect(function(player)
	save(player)
	loaded[player] = nil
end)

-- when the server closes, save everyone, and wait until every save is done
game:BindToClose(function()
	for _, player in Players:GetPlayers() do
		task.spawn(save, player)
	end
	while saving > 0 do
		task.wait()
	end
end)

-- and every 2 minutes, in case the server crashes
while true do
	task.wait(120)
	for _, player in Players:GetPlayers() do
		task.spawn(save, player)
	end
end

Every value you add to the leaderboard is saved too: wins, a level, the obby stage of our checkpoint script. Both scripts come from our Roblox scripts to copy and paste, where the others work with them.

How it works

  • One store, one key per player. GetDataStore("PlayerData") opens the store, and each player's values sit together under Player_ and their user ID. Coins and a stage took 24 bytes in our test.
  • Loading never guesses. It tries 3 times, 2 seconds apart, then asks the player to rejoin, so nobody plays with empty data that would save over their real data.
  • Saving copies the leaderboard into a table and writes it with SetAsync, inside pcall: a failed save warns in Output instead of stopping the script.
  • It saves 3 times: when a player leaves, every 2 minutes in case the server crashes, and when the server closes, in BindToClose, which waits for every save still running. Roblox gives those functions 30 seconds.
  • Other scripts can wait for it, and save through it: it sets a Loaded attribute on each player, false, then true once their data is in, and adds a SavePlayerData function. Our developer product script calls it to save a purchase before confirming it, as Roblox's player data guide advises.

Test that it saves

  1. Press Play. Your coins show at the top right: 0 the first time.
  2. Click Client/Server to switch to Server. In the Explorer, open Players, your name and leaderstats, select Coins, and set its Value to 100 in the Properties window.
  3. Stop (Shift+F5), then press Play again: your 100 coins are back.

Change it on the Server. A value changed in Client mode, or by a LocalScript, never reaches the server, which saves its own: in our test, 9999 coins set on the client were saved as the server's 4242.

Data not saving? Check these

  • Studio access is off, or the game isn't published. Turn it on as above.
  • The change happened on the client. Change values on the server: in Server mode, or from a Script. A LocalScript can ask the server with a RemoteEvent.
  • A LocalScript opens the data store. Only Scripts can: Output says DataStore can't be accessed from client.
  • It saves something a data store can't hold. Numbers, text, true or false, and tables of those. A Vector3, Color3, CFrame or part fails with error 104, like Cannot store Vector3 in data store, or Cannot store Dictionary when it's inside a table. Save the numbers in it, like a position's X, Y and Z.
  • A key is longer than 50 characters: error 102.
  • Output says "DataStore request was added to queue". The game asks too often, usually for the same key, so requests wait. In our test, 10 writes at once to one key all landed, about one a second. Save on a timer, not on every change.
  • It saves only when a player leaves. Save in BindToClose too, as the script above does: when Roblox shuts a server down, it waits up to 30 seconds for those functions. In our Studio test, a save started as the player left still finished when we pressed Stop, so it isn't always the cause.
  • Loading and saving use different names for the store or the key. They must match exactly.
  • Roblox's data stores are down. status.roblox.com lists Data Store among its services. The script above asks joining players to rejoin rather than play with empty data.

DataStore limits

LimitHow much
Data in one key4 MB. Coins and a stage took 24 bytes.
Key and store names50 characters
One server, a minute60 reads and 60 writes, plus 40 of each per player in it
The whole game, a minute300 reads, plus 40 per player online; 300 writes, plus 20 per player online
One key, a minute25 MB read, 4 MB written
Requests waiting30 per queue; more are dropped (errors 301 to 306)
Storage500 MB, plus 1 MB per player who ever joined
Old versionsOne for each hour a key was written, kept 30 days after it's replaced

The saving script makes one read when a player joins and about one write per player every 2 minutes, far below. Studio playtests have limits of their own, which can be lower.

SetAsync or UpdateAsync?

SetAsyncUpdateAsync
What it doesWrites your value over what's savedReads what's saved, gives it to your function, writes what it returns
Two servers at onceThe last write winsRuns your function again on the newer value
To cancelNot possibleReturn nil
Counts asA writeA read and a write
Use it forReplacing a value from the server that holds itA change that depends on what's saved

The saving script uses SetAsync: a player's data lives on the server they're in, and the save replaces it whole. Roblox advises UpdateAsync when the new value depends on the saved one or several servers may write a key, like the change line further down. Its function can't wait: no task.wait inside.

Session locking and ProfileStore

One case the script doesn't cover: a player leaves a server and joins another before the first one's save lands, often while teleporting. The second server loads old data, and its next save erases what the first one saved. In games with trading, that's how items get duplicated.

Session locking stops it: the server holding a player's data marks their key, and other servers wait. For coins, stages and wins, the rare loss is small; for trading, rare items and teleports between places, it isn't. For those, use ProfileStore, a free, open-source module by loleris and the successor to ProfileService: it locks sessions and saves every 300 seconds by default. Roblox advises checking a module's upkeep before adopting it, and calls DataStore2 a legacy library not to use in new games.

See, change or reset a player's data

Without code, live games included: on create.roblox.com, open Creations, your game, then Configurations, Data Stores Manager. Click PlayerData and search for Player_ plus their user ID, the number in their profile's address. You see the value and its versions: Revert brings back an older one, and the key's Action menu has Mark for Deletion.

In Studio, with Studio access on: press Play, click Client/Server to switch to Server, then paste one of these in the command bar (Script tab, or Ctrl+9, ⌘9 on a Mac), put the player's ID in place of 123456789, and run it.

Command bar, in Server mode: change a saved value
game:GetService("DataStoreService"):GetDataStore("PlayerData"):UpdateAsync("Player_123456789", function(data)
	data = data or {}
	data.Coins = 500
	return data
end)
print("Saved")
Command bar, in Server mode: reset a player
game:GetService("DataStoreService"):GetDataStore("PlayerData"):RemoveAsync("Player_123456789")
print("Reset")
  • Only while they're not playing. A server holding their data saves it back when they leave: in our test, a reset key came back.
  • Everyone at once: rename the store in the saving script, like "PlayerData2", and everyone starts fresh. Then mark the old store for deletion in the Data Stores Manager; Roblox keeps it 30 days in case you restore it.
  • Undo: Roblox keeps a key's older versions, one for each hour it was written, for 30 days after they're replaced. Revert brings one back.

Right to Erasure messages

A Roblox message titled [Important] Right to Erasure - Action Requested means a player of your game asked Roblox to delete their data. Delete their key as above, or let Roblox do it: in the Data Stores Manager's RTBF Deletion tab, click Create template, pick Standard Key, type PlayerData as the Data Store and Player_{UserId} as the Key Pattern, leave Scope as it is (global), and click Create. Roblox then deletes the matching key itself when it handles a request. {UserId} must be written exactly so, and Roblox advises checking the data is gone within 30 days.

How we tested it

On 17 November 2026, in a published test game in Roblox Studio, with the two scripts above unchanged:

  • Coins set to 4242 on the server were saved when the playtest stopped, and loaded at the next one.
  • Coins set to 9999 on the client never reached the server: 4242 was saved.
  • A LocalScript asking for the data store got "DataStore can't be accessed from client".
  • A Vector3, a Color3, a CFrame, a part and a table holding a Color3 each failed with error 104, a 51-character key with error 102.
  • 10 writes at once to one key printed the queue warning 9 times; all 10 landed, the last after 9 seconds.
  • On a playtest's server, the change line turned a player's saved 5100 coins and stage 3 into 500 coins and stage 3, and the reset line left the key empty.
  • A key reset while its player was in the game came back when they left.
  • Without BindToClose, a save started as the player left still finished when we pressed Stop.
  • Test purchases were in the data store a second after we clicked Buy. When a save failed, the coins were taken back until Roblox delivered the purchase again.

The Data Stores Manager's labels were checked in the Creator Hub the same day. Not tested, and taken from Roblox's docs: a live server shutting down, one player on two servers at once, and Roblox's automatic RTBF deletion.

Made by ClipClip (ours)Your players keep their progress. Now bring moreClipClip turns a few minutes of your gameplay into vertical clips for TikTok, Reels and Shorts, with a hook and captions.See what ClipClip makes

Questions

What is a DataStore in Roblox?

Roblox's storage for what must last between visits, like coins, levels or items. Each game has its own data stores, and inside one, each value sits under a key, usually one per player.

How do I save player data in Roblox Studio?

Publish the game, turn on Enable Studio Access to API Services in File, Experience Settings, Security, and add a saving script in ServerScriptService that loads a player's data when they join and saves it when they leave, every few minutes and when the server closes.

Why isn't my data saving in Roblox Studio?

Most often Studio access is off, the value was changed on the client (in Client mode or by a LocalScript), or the save failed with an error in Output. The checklist on this page covers each one.

What does Enable Studio Access to API Services do?

It lets playtests in Studio use your game's real data stores. Turn it on for a test game. On a game people play, Roblox advises testing on a copy, since Studio would read and write their real data.

Can a LocalScript use a DataStore?

No, only server Scripts can. A LocalScript gets the error "DataStore can't be accessed from client". Send what the player did to the server with a RemoteEvent and save from there.

How often should I save player data?

When a player leaves, when the server closes, and every few minutes in between. Roblox's tutorial suggests every 30 to 120 seconds; the script on this page saves every 2 minutes. Saving on every change hits the limits.

What does "DataStore request was added to queue" mean?

Your game asked faster than Roblox allows, usually for the same key, so requests are waiting their turn. They still run, more slowly. If the queue fills (30 requests), the next ones are dropped. Save less often.

What is the DataStore limit per player?

4 MB per key, so 4 MB per player with one key each. A server can also make 60 reads and 60 writes a minute, plus 40 of each for every player in it.

Should I use SetAsync or UpdateAsync?

SetAsync to replace a value from the server that holds it, like a player's data when they leave. UpdateAsync when the new value depends on the saved one, or several servers may write the same key: it reads before it writes.

What is session locking in Roblox?

A way to make sure only one server holds a player's data at a time, so a server with old data can't save over newer data. It matters for trading and valuable items; ProfileStore does it for you.

Should I use ProfileStore, ProfileService or DataStore2?

For coins, stages and wins, a script like this one is enough. For trading or valuable items, ProfileStore, the successor to ProfileService, adds session locking. Roblox calls DataStore2 legacy and says not to use it in new games.

How do I reset a player's data on Roblox?

In the Creator Hub's Data Stores Manager, open their key and choose Mark for Deletion, or run the reset line on this page in Studio. They must not be playing, or their server saves their data back when they leave.

What is a Right to Erasure request on Roblox?

A Roblox message, "[Important] Right to Erasure - Action Requested", saying a player of your game asked Roblox to delete their data. Delete their key, or set up an RTBF template so Roblox deletes it by itself.

Are Roblox data stores down?

Check status.roblox.com, which lists Data Store among Roblox's services. While they're down, the script on this page asks joining players to rejoin instead of letting them play, and save, with empty data.

Sources

Grow your Roblox game.

ClipClip is the all-in-one marketing platform for Roblox games. Coming soon.

Notify me