Roblox DataStoreService persistence: load on join, save on leave and BindToClose, UpdateAsync vs SetAsync, session locking and OrderedDataStore leaderboards. Use for lost player data, items duplicating after teleport, or "too many requests" errors. Not for engine-neutral saves (`save-systems`), Luau basics (`roblox-luau`) or economy numbers (`roblox-simulator-economy`).
Ships in gamedev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Persist data across sessions without losing or duplicating it. All DataStore calls are network
requests from server Scripts; they can fail, be throttled, and race with another server writing
the same key.
DataStoreService, GetDataStore, and any
profile or session library before writing new code. If the project already uses one, extend it;
two systems writing the same key is the most common cause of rollbacks.StudioAccessToApisNotAllowed.UserId, never by name: "Player_" .. player.UserId.pcall. On a failed load, mark the session as not loaded and refuse
to save, so defaults never overwrite real data.PlayerAdded, save on PlayerRemoving and in game:BindToClose, plus a periodic
save (every 60-120 s), never on every value change.UpdateAsync and session ownership. UpdateAsync reads the latest value before
writing; session ownership (in references/sessions-and-limits.md) stops a stale server from
writing an old snapshot over newer progress.OrderedDataStore only for numeric rankings (leaderboards).execute_luau on the Server datamodel. Without
MCP, ask the user to do join, change, leave, rejoin in the test place and report the value seen
after rejoining and any Output warnings. Rate-limit behavior needs Team Create, not Run mode.# Every DataStore call should sit inside pcall; this lists the lines to inspect by hand.
rg -n ":(GetAsync|SetAsync|UpdateAsync|IncrementAsync|RemoveAsync|GetSortedAsync)\(" src
rg -n "BindToClose" src # expect at least one save-everyone handler
rg -n ":SetAsync\(" src # each one on a player profile key needs a reason
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local store = DataStoreService:GetDataStore("PlayerData")
local DEFAULT = { Coins = 0, Level = 1 }
Players.PlayerAdded:Connect(function(player)
local key = "Player_" .. player.UserId
local ok, data = pcall(function()
return store:GetAsync(key)
end)
if not ok then
warn("Load failed for", player.UserId, data) -- network failure, not a new player
player:SetAttribute("DataLoaded", false)
return
end
player:SetAttribute("DataLoaded", true)
applyToLeaderstats(player, data or table.clone(DEFAULT)) -- nil means a genuinely new player
end)
This callback ignores old, so on its own it can overwrite newer progress from another server.
Before shipping, add the session check from references/sessions-and-limits.md inside the
callback, or use a vetted profile library.
local function savePlayer(player)
-- `~= true` also covers a player who left while GetAsync was still in flight.
if player:GetAttribute("DataLoaded") ~= true then return end
local key = "Player_" .. player.UserId
local newData = gatherDataFor(player) -- plain, JSON-serializable table
local ok, err = pcall(function()
store:UpdateAsync(key, function(old)
-- Must not yield and may run more than once. Return nil to cancel the write
-- when this session no longer owns the key.
return newData
end)
end)
if not ok then warn("Save failed for", player.UserId, err) end
end
Players.PlayerRemoving:Connect(savePlayer)
game:BindToClose(function()
local players = Players:GetPlayers()
local remaining = #players
for _, player in players do
task.spawn(function()
savePlayer(player)
remaining -= 1
end)
end
while remaining > 0 do task.wait() end -- the server waits at most 30 s in total
end)
local function withRetry(fn, attempts)
attempts = attempts or 3
for i = 1, attempts do
local ok, result = pcall(fn)
if ok then return true, result end
if i < attempts then task.wait(2 ^ i) end
end
return false
end
A failed write does not prove the write did not happen; the server may only have missed the
response. Re-running an UpdateAsync that writes the full state is harmless; re-running
IncrementAsync can add twice. When the outcome matters, confirm with an uncached read
(DataStoreGetOptions with UseCache = false) before retrying.
local board = DataStoreService:GetOrderedDataStore("Coins")
pcall(function() board:SetAsync("Player_" .. player.UserId, coins) end) -- on change, throttled
local ok, pages = pcall(function()
return board:GetSortedAsync(false, 10) -- false = descending, highest first
end)
if ok then
for rank, entry in pages:GetCurrentPage() do
print(rank, entry.key, entry.value)
end
end
Values must be integers. For a few specific players (friends, a party), BatchGetAsync(keys)
reads up to 100 keys in one request instead of paging the whole board.
SetAsync races between servers. During a teleport or fast rejoin two servers can hold the
same player; the last blind write wins. Use UpdateAsync with session ownership.UpdateAsync callback. The callback cannot yield, and
Roblox re-runs it when another server changed the key first, so granting items, firing remotes
or incrementing counters inside it can happen twice. Act after the call returns.BindToClose save. Players in the server at shutdown lose everything since the last
periodic save.GetAsync caches a key for about four seconds after the first read, so an
immediate re-read after a write may return the old value.Vector3, CFrame, Color3 and Instances to
plain tables first.DataStoreKeyInfo is nil for ordered stores. They have no versioning or metadata; use a
regular DataStore when you need those.MemoryStoreService, not DataStores.references/sessions-and-limits.md before shipping save code or when debugging rollbacks,
duplication, or throttling: session locking, versioning and metadata, pagination, request
budgets, storage limits, Right to be Forgotten, and Open Cloud.roblox-luau: services, events, and the server/client model.roblox-simulator-economy: repairing loaded values and offline earnings.save-systems: engine-neutral serialization, slots, and migration.Last verified: 2026-11-11.
UpdateAsync spends from both read and write. Per-server limits still apply.BindToClose handlers get 30 seconds in total. Studio Run mode uses its own lower static
limits; test rate limits in Team Create.Sources: https://create.roblox.com/docs/cloud-services/data-stores,
https://create.roblox.com/docs/cloud-services/data-stores/error-codes-and-limits,
https://create.roblox.com/docs/reference/engine/classes/GlobalDataStore,
https://create.roblox.com/docs/reference/engine/classes/DataModel (BindToClose),
https://devforum.roblox.com/t/unifying-data-stores-open-cloud-and-game-apis-and-increasing-storage-limits/4739240.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/gamedev:roblox-datastoresfrom gamedev
npx claudepluginhub cirobarone78/games-skill --plugin gamedev80 skills in this plugin
/ai-behavior-trees-utility-aiEngine-neutral behavior tree and utility AI code for NPCs in any language: Blackboard, reactive composites, decorators and response-curve scoring. Use when an enemy keeps chasing after losing sight, restarts its action every frame or flip-flops between choices. Not for FSMs, steering or pathfinding (`game-ai`) or Unreal BT, EQS and StateTree (`unreal-behavior-trees`).
/audio-designEngine-neutral game audio technique: bus layout, volume sliders in decibels, loudness, ducking music under dialogue, adaptive music and SFX variation, with Godot, Unity and FMOD/Wwise mappings. Use when mixing a game, making music react to combat, fixing repetitive footsteps or beat sync, or a mix that clips or pumps. Not for the Godot audio API (`godot-audio`).
/bevy-ecsBuilds and debugs Bevy 0.20 games in Rust: components, Query and Commands systems, schedules, States, observers and headless tests. Use when Cargo.toml depends on bevy, on a B0001 query-conflict panic, or pre-0.20 code (EventReader, SpriteBundle). Not for engine-neutral AI, generation, physics or shaders (`game-ai`, `procedural-gen`, `physics-tuning`, `shader-programming`).
/camera-systemsBuilds and tunes game cameras, engine-neutral with Godot and Cinemachine 3 mappings: 2D follow with deadzone and look-ahead, third-person orbit, first-person look and split-screen. Use when the camera lags, jitters while following, shows past the level edge, clips through walls or changes with frame rate. Not for shake (`game-feel`) or physics timestep jitter (`physics-tuning`).
/card-gameDesigns card games and deckbuilders in any engine: cards as data with one effect interpreter, deck zones, a trigger stack and seeded shuffles. Use for a Slay the Spire- or Balatro-like or a TCG, or cards that duplicate or streaky shuffles. Pair with the engine skill for card data and hand UI (`godot-resources`, `godot-ui-control`, `unity-scriptableobjects`). Not for grid crawlers (`roguelike`).
/create-game-assetsPlans, generates or sources, and validates consistent game art: style guides, sprites, pixel art, tilesets, icons and textures, with QA and licence records. Use when making or AI-generating game art, fixing fake transparency, or checking Steam AI disclosure. Not for engine import (`godot-tilemap`, `godot-animation`, `unity-tilemap-2d`), UI layout (`game-ui-ux`) or sound (`audio-design`).