FFORGE

Guide · 9 min read · Updated November 2026

Roblox DataStore script with session locking: what AI should write, and how to check it

Most "DataStore script" tutorials and most AI-generated saving code share one bug: two servers can hold the same player's data at once, both save, and the player ends up with duplicated pets or a rolled-back purchase. The fix is a session lock. This guide shows what a correct saving module looks like, the prompt that gets an AI agent to write one inside your Studio, and the five things to check before you trust it.

The bug in most saving scripts

The usual script loads with GetAsync on join, keeps a table in memory, and writes it with SetAsync on leave and every minute. It passes every Studio test and fails in production, because production has more than one server. A rejoin after a crash, a teleport between places, or a slow PlayerRemoving on a shutting-down server means two servers hold the same key. Both save. Items duplicate, purchases roll back, and the Discord fills with "I lost my pet".

A session lock fixes it: loading writes "this server owns this key" into the data itself, a second server that sees a fresh lock waits or gives up, every save checks the lock still belongs to this server, and leaving releases it. You can hand-roll that with UpdateAsync, or use a module that already does it.

What correct looks like: ProfileStore

Forge's default, from its datastores playbook, is ProfileStore (by loleris): session locking, autosave, BindToClose and reconcile built in. The shape of the module Forge writes:

Studio needs Game Settings ▸ Security ▸ Enable Studio Access to API Services turned on, or ProfileStore prints that API services are unavailable and nothing persists.

The prompt

Add saving to my game with ProfileStore (insert the Creator Store module by loleris if it is
missing). One module, ServerScriptService.Modules.PlayerData, owns every read and write: a
TEMPLATE with Coins, Unlocks, Equipped and PurchaseIdCache, StartSessionAsync with a Cancel
when the player leaves, Reconcile, AddUserId, kick on a failed session, EndSession on
PlayerRemoving, and a WaitFor the remotes call. Use Store.Mock in Studio so tests do not
touch live keys. Remind me to turn on Studio access to API services. Test: earn coins, stop,
start again, confirm they are back. Screenshot the leaderboard after the rejoin.

This is the DataStore saving with session locking prompt; the button on that page opens Forge with it typed in. Forge reads your place first: if you already have ProfileService, ProfileStore or your own module, it keeps it and matches the API.

When ProfileStore cannot be installed

Some places block Creator Store inserts, and some developers want no third-party module. Forge's fallback (its datastores-fallback playbook) is a hand-rolled module with the same public API and a real lock:

Five checks for any AI-written DataStore script

  1. Search the place for DataStoreService. It should appear in exactly one module. A second script with GetAsync is a dupe waiting to happen.
  2. Find the lock. ProfileStore's StartSessionAsync, or an UpdateAsync transform that writes a session id and cancels on a foreign lock. GetAsync followed by SetAsync is not a lock.
  3. Look for pcall. Every store call is wrapped, with a warn that names the player and the reason. A silent failure is worse than a loud one.
  4. Check the template. It has every field the game saves, including PurchaseIdCache, and nothing that is not plain data.
  5. Run the rejoin test with API access on. Earn, stop, start, confirm. Then run it with two clients and a trade or purchase, and confirm one copy of everything.

Forge finishes the saving step with that rejoin test and a screenshot, not just a clean console. If you are checking code from a script generator instead, the AI script generator guide has the wider checklist.

What it costs

Saving is one system-sized message: about 120 to 450 credits ($1.20 to $4.50) on Sonnet 5.5 including the rejoin test, per the pricing page ranges. The ProcessReceipt tie-in for developer products is a separate step of 100 to 400.

Questions

Why does plain GetAsync and SetAsync duplicate items?

GetAsync takes no lock. If a player is on server A, trades a pet, and server B (a rejoin after a crash, or a teleport) loads the same key before A saves, both servers now hold a copy. Whichever saves last wins, and the pet exists twice or the trade is undone. A session lock makes the second load wait or cancel.

Is ProfileStore safe to use from the Creator Store?

ProfileStore by loleris is the standard choice and the Creator Store copy is from the verified creator. Forge inserts it by asset id rather than retyping 65 KB of module, checks it arrived as a ModuleScript, and never edits it.

I already use ProfileService or my own module. Will AI replace it?

It should not, and Forge does not. It reads the place first; an existing data module is kept and its API matched. Migrating a live game's saves to a new store or key format is something to ask for explicitly, after a backup.

Why must the purchase id be saved with the data?

ProcessReceipt should return PurchaseGranted only after the grant and the receipt id are in the same saved profile. A separate purchase-history store can succeed while the data save fails, losing a paid purchase, or the reverse, granting twice on Roblox's retry.

Related guides

Let Forge write and test it in your place. Pair your Studio, press Build on the prompt, get the rejoin screenshot back. Trial credits, no card. Build it in Forge →