Data Stores
Use DataStoreService to persist player data (like coins, inventory) across sessions. Access data stores on the server only.
local DSS = game:GetService("DataStoreService")
local store = DSS:GetDataStore("PlayerData")
local function loadUser(userId:number)
local ok, data = pcall(function()
return store:GetAsync(tostring(userId))
end)
if ok then
return data or {coins=0}
else
warn("Load failed:", data)
return {coins=0}
end
end
Notes: Reads/writes are throttled; handle errors and backoff. Prefer
UpdateAsync for atomic writes and consider OrderedDataStore for leaderboards.