DataService owns every save and every DataStore call. It session-locks profiles with ProfileStore, upgrades old data, mirrors it into private Charm atoms and exposes the write paths other services use. The data shape lives in the pure shared modules PlayerData.luau and AccountData.luau.
DataService is a folder module: init.luau holds the join and leave, get, waitFor, update, the forced saves and the one public table, and private parts sit beside it (State, Atoms, Stored, Account, Slots, Sandbox, Versions, Ordered, Shared, Budget). Callers require DataService only. tests/core/server/Services/DataService.spec.luau runs the real service over the test engine kit's ProfileStore stand-in.
Save slot, account or game-wide data?
- PlayerData: progress in one slot
Currency, items, settings, stats, flags and purchase records. Store
PlayerData; slot 1 keeps the original keytostring(userId), other slots use<userId>_slot<n>. Write throughDataService.update; staff support rewrites a save no server holds only throughDataService.rewriteSave.- AccountData: once per account
The daily reward streak, redeemed codes, referrals, the tutorial's progress, gifts received and once-per-account claims not yet settled (
claims), independent of the chosen save slot. StorePlayerAccounts, keytostring(userId), with its own session lock. Write throughDataService.updateAccount; a reward paid once per account goes throughClaimService.claim.- Shared values
Game-wide records such as the ban list, watchlist and staff suspensions, one key each in the
SharedDataStore. UsegetSharedandupdateShared; their updaters must have no side effects because UpdateAsync may rerun them.- Ordered scores
Leaderboards use DataService's ordered-store helpers.
Rules/Leaderboardsencodes scores before storage; other modules never open their own DataStores.- Unsaved state
Public server facts in SharedState, private per-player atoms in their owner with a private SyncService key, and local interface state in ClientState. Do not save what config can derive.
Changing a store name or the slot-key rule points players at different data. Treat it as a destructive save-format decision, with the team's agreement; a normal feature never changes those identifiers.
How a profile loads safely
The account loads on join; with multiple slots, the slot loads after the player chooses it. DataService.loaded fires only when both profiles are ready. The slot is migrated on a copy before Reconcile fills new defaults. A missing or failing migration, or a save newer than this build, ends the session and refuses the player without overwriting the stored data. While the DataStore is down, a load waits (ProfileStore retries until the player leaves) and nothing is written over the save.
get returns data or nil without yielding; waitFor yields until loading, departure or timeout, woken by loaded for that player or by their leaving rather than by polling. A save-picker player and a migration-holding-server arrival have no loaded slot: reads return nil and writes refuse not_loaded.
Writing immutable data
Only DataService.update(player, updater) changes PlayerData. Clone the top table and every nested table you modify; return the new table. Returning the original means no change and skips the atom write. Never yield inside the updater. Currency uses CurrencyService, and purchases use MonetizationService, which own their additional rules.
DataService.update(player, function(data) local next = table.clone(data) next.stats = table.clone(data.stats) next.stats.rounds = (data.stats.rounds or 0) + 1 return nextend)Use DataService.watch(player, fn) for one player's changes and retain its stop function. Watchers are coalesced to the newest state once per frame. SyncService sends a player's changed keys to their client at most 20 times a second, and flushes only after a synced value was written (or a player started syncing), so an idle server does no diffing. Visit-final writes belong in DataService.unloading, before the listener yields: it runs before the final profiles read their data. PlayerRemoving listeners have no equivalent ordering guarantee.
Adding a field or changing its shape
Choose the profile
Use PlayerData for slot progress and AccountData for once-per-account rules.
Add type and default
Update its exported type and frozen template. Reconcile fills the additive default into older saves; no schema bump is needed.
Verify the default
Extend the pure module's specs and check the client contract. Prefer existing bounded stats and flags maps for small counters.
Changing lastSeenAt, playtimeSeconds, currencies or purchases.receipts also requires checking Rules/Saves.summary and DataService.receiptInOtherSlot: they inspect other slots as stored, before migrations. The Template's data-field skill covers both profiles.
The Template's PlayerData is at schema version 5. The step from version 1 drops parkour, hatching and companions, the fields of kits the Template removed as game-specific, on a copy like any migration. Pets hatched before then stay in the save as inventory stacks of retired items, which never activate. The step from version 2 drops building (saved layouts and blueprints) and the inventory's replay sequence for the removed building source. The step from version 3 drops the saved settings and control overrides of the combat, rounds and first-person kits. The step from version 4 strips the old sideways nudge from every placement in PlayerData.layout (the player's HUD layout per device class, { [class]: { [widgetId]: { region, order } } }, written only by SettingsService.saveLayout; see the HUD layout), and drops anything in a saved layout that is not whole, which would have stopped the save loading; a save with no layout is untouched. As with any bump, a server still on an older build refuses a save already at version 5.
Purchase receipts are confirmed before Roblox is told granted
MonetizationService checks the receipt id, including other slots, runs the server's product handler, records the receipt and calls DataService.saveAndConfirm. Roblox receives PurchaseGranted only after a confirmed real save contains that receipt. A timeout or unavailable save leaves the purchase for retry. A repeated recorded receipt is confirmed without granting the reward again.
saveAndConfirm defaults to 15 seconds. Forced saves (saveAndConfirm, saveAccountAndConfirm, saveSoon) share a six-second per-profile spacing, coalescing bursts into one queued save; force a save only of a profile that changed. saveSoon(player, only?) saves both profiles, or only "account" or "slot". Ordinary writes rely on ProfileStore's normal saving; a gift calls saveSoon. The reward can be applied in memory before confirmation: the guarantee concerns the acknowledgement sent to Roblox.
Once-per-account claims commit the account first
A reward taken once per account whichever slot is played (a redeem code, a daily reward, a referral payout or welcome, a subscription period, the Premium bonus, the group reward, a staff support grant) has its marker in the account and its reward in the slot, two profiles that save apart. Every such reward goes through ClaimService.claim (Rules/Claims), so a crash at any point pays it exactly once:
Record
One
updateAccountwrites the service's own marker and the claim (AccountData.claims: id, kind, analytics reason, rewards of any kind). It refuses with nothing written whatRewardService.fitsrefuses (at_cap,inventory_fulland the rest), so a service's marker is never spent for nothing, andbusywhile 50 claims already wait.Account first
Nothing is paid until
DataService.saveAccountAndConfirmsees the claim in a confirmed account save, so a slot never holds a payment whose marker the account lost.Pay with a receipt
One
RewardService.grantpays every reward whole and, in the same write, recordsclaim-<id>in the slot'spurchases.receipts. A claim whose receipt is already in this slot or another slot is settled unpaid; an unreadable other slot leaves it waiting.Settle
Once a confirmed slot save holds the receipt, the claim leaves the account.
The claimed reward lands a moment after the answer (one forced account save), not in the same frame. A real claim forces two saves, the account and then the slot; a test-mode claim forces none, since a claim there lands on the copies and is paid at once. A service that must act on a payment registers ClaimService.onPaid(kind, fn), which must not yield. AccountData.claims[].rewards may hold any kind of reward; a claim saved in the old { currency, amount } shape is read as currency, with no migration.
A developer's support grant (grant <user> <kind> <id> [amount]) reaches an offline account as a supportGrant account message; the server holding the account turns it into a claim of kind support in the write that removes the message, so it too is paid exactly once.
Request budgets
Roblox limits DataStore requests per server per minute by request type. Every store request
DataService makes is counted by the type it spends (DataService.countRequest: a session start
or account message as UpdateAsync, each sorted page as GetSortedAsync, each retry again), and
the Roblox/MemoryStore module counts the request units of every MemoryStore call there, since MemoryStore has no quota to read. The
developer command budgets shows the last minute's counts beside the engine's budget
(DataService.requestBudgets, from GetRequestBudgetForRequestType). ProfileStore's own
auto-saves spend the budget without appearing in the counts.
What the default switches spend on a 100-player server in a minute, worked out from the code
(the Template's docs/engineering/Performance.md): about 40 UpdateAsync auto-saves (two
profiles a player, every 300 seconds) and 4 for each player who joins and leaves, against a limit
of 1,060; about one GetAsync (staff suspensions, only while ranked staff are in the server); at
most 5 ordered-store writes per player and 5 board reads; 200 MessagingService subscriptions
(ProfileStore subscribes once per loaded profile, plus at most three bus topics) against 820; and
no MemoryStore request on an ordinary server. These budgets are per server, so 300 servers change
none of them. No save is polled: every wait yields on its event with a timeout.
Test mode writes a copy
beginSandbox copies both slot and account data; get, update, getAccount and updateAccount then use those copies. Ending the sandbox discards them. Leaderboards, badges and other external effects must skip sandboxed players. Real visit bookkeeping and real purchases use the owner's synchronous real-profile windows (onReal or withRealProfile); saveAndConfirm always checks the real save. The leaderboards' test-mode start hook reads the real save through onReal, and a control rebind made in test mode changes each save's own bindings, so the real save keeps its other rebinds.
Support writes are new versions
Staff roll a save back or correct one value offline with the admin suite's save commands (Rolling a save back). DataService.listSaveVersions and readSaveVersion use ProfileStore's version query (refused in Studio, whose mock store keeps no versions). DataService.rewriteSave is the only write: it refuses while the player is in this server or another server holds the session lock, opens a short session of its own (cancelled if the player joins), upgrades the stored save exactly as a load does (upgradeSave), applies the change and ends the session. The write is a new version, so it can itself be restored; nothing uses Profile:SetAsync, which ignores the lock.
Erasure requests
Roblox sends the experience owner a daily list of right-to-erasure requests; everything held about the user must be gone within 30 days. For a game on the Template:
Saves, once per game
In the Creator Hub's Data Stores Manager (RTBF Deletion tab), add deletion templates with scope
global: storePlayerDatawith keys{UserId}and{UserId}_slot2through{UserId}_slot10(every possible slot, since lowering the slot count keeps the data), andPlayerAccountswith key{UserId}. Roblox then deletes them with each request.Leaderboards, per request
lbforget <userId>removes the user from every board's current period and all-time board, and from recent past periods in the background. It does not reach older periods, boards removed from config or any board while leaderboards are off; clear those by hand.Moderation records, per request
unwatch <userId>drops them from the watchlist; their saved ban entry goes only withunban <userId>, which also lifts the Roblox ban.The Blockout platform, per request
Send the user id to the studio: the platform holds their feedback, transfers and studio bans, and has no erasure route a game can call.
Verify
Check everything is gone within the 30 days. Other players' saves that name the user by id stay; MemoryStore entries expire on their own.
Start consumers only after data loads and clean them up.
Test pure migrations and request runtime checks.
Updated