A one-page reference for the DataStore calls you use most. Keep it open while you script.
The calls
| Call | Use it for | Notes |
|---|---|---|
GetAsync(key) | Read a value | Returns nil if the key does not exist |
SetAsync(key, value) | Overwrite a value | Can clobber changes from another server |
UpdateAsync(key, fn) | Change a value safely | fn gets the latest value, return the new one |
IncrementAsync(key, n) | Add to a number | Good for simple counters |
RemoveAsync(key) | Delete a key | Useful for data requests and tests |
The safe pattern
local function safe(fn) for attempt = 1, 4 do local ok, result = pcall(fn) if ok then return true, result end task.wait(attempt) end return false end local ok = safe(function() return store:UpdateAsync("user_" .. player.UserId, function(old) old = old or { coins = 0 } old.coins += 10 return old end) end) When to save
- On a timer (every 2 to 5 minutes)
- In
PlayerRemoving - In
game:BindToClose - After big events (a purchase, a level up), not every small change
Do and don't
- Do key by
UserId, never by username. - Do keep one table per player instead of many keys.
- Do not save if the load failed, or you will overwrite real data with defaults.
- Do not trust the client for any value you save.
- Do version your store name (
PlayerData_v1) so you can migrate later.
Limits to check
Key length, value size and request budgets are limited and can change. Check the current Roblox documentation for exact numbers before you design around them.
More
The full free module is here: 5 DataStore mistakes + free module. My Roblox Game Starter Kit has tested datastore, shop and leaderboard scripts, and LAUNCH25 gives 25% off until Dec 17: Roblox Game Starter Kit.
