Saving a Player's Progress in Roblox
The short answer: Scores live in a folder called leaderstats that your script builds inside each player โ that is what the scoreboard in the game shows. But leaderstats vanishes when a player leaves. For progress that stays, the server saves it with DataStore, Roblox's saving service: load a player's saved value when they join, save it when they leave, and wrap every save and load in pcall because those calls travel over the network and can fail.
Step 1: leaderstats โ the scoreboard
This is the leaderboard script from Roblox's own points tutorial. Put a Script named Leaderboard in ServerScriptService:
-- Put this Script in ServerScriptService. Name it Leaderboard.
local Players = game:GetService("Players")
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats
end
Players.PlayerAdded:Connect(onPlayerJoin)What it does: every time a player joins (the PlayerAdded event from page 5), the script builds two things with Instance.new โ a Folder named leaderstats inside the player, and inside that folder an IntValue named Points starting at 0. Roblox shows the values inside a folder named leaderstats on the game's scoreboard automatically โ that exact name is the magic word. Other scripts change the score by changing Points.Value, exactly like the points plate patterns in this series.
The catch: leaderstats is rebuilt from scratch every join. Earn 500 points, leave, come back โ you are at 0 again. That is what DataStore fixes.
Step 2: DataStore โ saving for real
A data store is Roblox's way to keep data between sessions โ the documentation's own examples are things like a player's inventory or skill points. Data stores belong to the whole game: any place in the game, on any server, reads and writes the same data. Only server Scripts can use them โ a LocalScript that tries causes an error, which is exactly right for page 7's lesson: saving is the server's job, never the player's device's.
Add a second Script in ServerScriptService, named SavePoints:
-- Put this Script in ServerScriptService. Name it SavePoints.
-- It works together with the Leaderboard script.
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local pointsStore = DataStoreService:GetDataStore("PlayerPoints")
local function loadPoints(player)
local leaderstats = player:WaitForChild("leaderstats")
local points = leaderstats:WaitForChild("Points")
local success, savedPoints = pcall(function()
return pointsStore:GetAsync("Player_" .. player.UserId)
end)
if success and savedPoints ~= nil then
points.Value = savedPoints
end
end
local function savePoints(player)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
return
end
local points = leaderstats:FindFirstChild("Points")
local success, errorMessage = pcall(function()
pointsStore:SetAsync("Player_" .. player.UserId, points.Value)
end)
if not success then
warn(errorMessage)
end
end
Players.PlayerAdded:Connect(loadPoints)
Players.PlayerRemoving:Connect(savePoints)Walking through it:
GetDataStore("PlayerPoints")opens (or creates) the store. Think of a store as a giant dictionary โ page 4's labeled boxes, kept by Roblox between sessions.- Each player's entry has its own key. Here the key is
"Player_" .. player.UserIdโ the player's unique account number, which never changes even if they rename their character. The documentation uses a player's UserId as the example key for exactly this reason. loadPointsruns when a player joins.WaitForChildmatters here: two scripts can wake up in either order, so this one waits for the Leaderboard script to build leaderstats before reaching inside it.savePointsruns onPlayerRemovingโ when a player leaves. It usesFindFirstChildinstead ofWaitForChild, and quietly gives up if the folder is missing, because you should never make a leaving player wait on a save that has nothing to save.- A brand-new player has nothing saved yet, so the load brings back nothing and they simply keep the starting 0.
Why every save wears a pcall
GetAsync and SetAsync are network calls โ your server asks Roblox's computers to fetch or store something. The data store guide is blunt about it: calls like these might occasionally fail, so you wrap them in pcall. pcall means "protected call": it runs the function, and if anything goes wrong it does not crash your script โ it hands you back success = false and the error message, so your game can warn you and carry on. An unwrapped save that fails takes the whole script down with it. A wrapped one just skips a beat.
Roblox's deeper player-data guide shows where the pros take this: keep the data in memory while someone plays, save when they leave, save again every few minutes in between as a safety net, and do a final save inside game:BindToClose() โ the hook that runs when a server shuts down, where save code gets about 30 seconds to finish. That same guide warns that its own full sample system is reference material, not code to drop into a game untested. Take the hint at every size: saving is the one system you test like you mean it, because a bug here does not crash a session โ it quietly eats somebody's progress.
Studio tests vs the live game โ read this before testing
By default, games tested in Studio cannot reach data stores at all. Your loads and saves will fail (your pcall catches the errors, so the game runs โ points just never persist). That is on purpose: Studio would be talking to the same data stores as your live game, and a test could overwrite real players' progress.
The data store guide gives the switch, for a published game:
- Open Studio's File menu, then Experience Settings.
- Go to Security.
- Turn on Enable Studio Access to API Services.
- Click Save.
And the guide's own warning, which matters more than the steps: do not enable this on a live game. Turn it on in a separate test version of your game, so your experiments can only ever touch test data. The honest summary:
- In Studio, toggle off (the default): leaderstats works; saving does nothing. Fine for testing gameplay.
- In Studio, toggle on, in a test copy of your game: saving really works, against the test copy's stores. This is how you test saving.
- In the live game: saving works for every player, loaded on join and stored on leave โ no toggle involved, because live servers are the real thing.
This page is part of the Roblox Luau series:
1. Installing Roblox Studio ยท
2. Your First Script ยท
3. Luau Basics 1: Variables, Numbers, and Words ยท
4. Luau Basics 2: Choices, Loops, and Functions ยท
5. Making Things Happen: Events ยท
6. Saving a Player's Progress ยท
7. The Player Talks to the Server ยท
8. Build a Whole Mini-Game ยท
9. Stay Safe and Keep Your Game Yours
Sources (official only; read in full November 7, 2026):
- Roblox Creator Documentation, tutorial Else/if practice with giving points (Coding Fundamentals) (create.roblox.com/docs) โ the leaderboard script pattern: a Folder named leaderstats parented to the player, an IntValue inside it, built when PlayerAdded fires.
- Roblox Creator Documentation, Data stores โ DataStoreService stores data that persists between sessions and is consistent per game across places and servers; GetDataStore(); keys such as a player's UserId; SetAsync, GetAsync, and UpdateAsync; network calls can fail, so wrap them in pcall; only server Scripts can access data stores (a LocalScript attempt errors); the Enable Studio Access to API Services toggle (File > Experience Settings > Security), off by default for Studio tests, and the warning not to enable it on a live game โ use a separate test version instead.
- Roblox Creator Documentation, Player data and purchasing systems โ load data once when a session starts and write it when the session ends, with periodic writes in between; the final write belongs in PlayerRemoving or BindToClose, and BindToClose callbacks have about 30 seconds; Roblox's own sample system is provided for reference and should not be used as-is without extensive testing.
The save/load script's logic was run on this machine against a small fake Roblox setup before this page was written: a test player joined, earned 70 points, left, and rejoined โ and the saved 70 points loaded back, exactly as this page describes. Roblox API code itself only runs inside Studio, so the scripts were also checked line by line against the documentation above. Checked November 7, 2026.