Saving player data is the first thing most Roblox games need, and the first thing that quietly breaks. This is a short, practical walkthrough of a DataStore setup that survives outages and does not lose progress.

1. Enable API access for Studio testing

Publish your place, then go to Game Settings > Security and turn on "Enable Studio Access to API Services". Without it, DataStore calls fail in Studio.

2. Use UpdateAsync, not SetAsync

SetAsync overwrites whatever is stored. If two servers touch the same key, the last write wins and data is lost. UpdateAsync gives you the current value and lets you return the new one:

local DataStoreService = game:GetService("DataStoreService") local store = DataStoreService:GetDataStore("PlayerData_v1") local function save(userId, data) local ok, err = pcall(function() store:UpdateAsync("player_" .. userId, function(old) return data end) end) if not ok then warn("Save failed:", err) end return ok end 

3. Retry with a delay

DataStore requests can fail because of throttling or short outages. Wrap calls in a small retry loop:

local function withRetry(fn, tries) for i = 1, tries do local ok, result = pcall(fn) if ok then return true, result end task.wait(2 ^ i) end return false end 

4. Save on leave and on shutdown

Connect Players.PlayerRemoving and game:BindToClose so players who leave, and servers that shut down, still write their data. Add an autosave every 60 seconds as a safety net.

5. Guard against duplicate sessions

If a player joins a second server before the first finished saving, items can be duplicated. Store a session lock (a server id and timestamp) in the data and refuse to load when another live server holds it.

6. Validate before you save

Check types and ranges on the server before writing. Never trust values sent from a client.

Want it ready-made?

I packaged these patterns (safe saving, session lock, shop, settings and leaderboard, with 30 logic tests) as a starter kit: https://agurokey.gumroad.com/l/aguro-key-game-starter-kit?utm_source=dev-to&utm_medium=post&utm_campaign=launch

Code LAUNCH25 gives 25% off until Dec 17. The tutorial above works fine without it.