ProfileStore: the library pros use

Replace a hand-rolled Roblox DataStore layer with ProfileStore, covering install with Wally, sessions, session locking, autosave, the Mock store and a one-time migration of Beacon Yard's saved coins.

Tool lesson, about 65 minutes, 10 steps

By the end you can

  • Install ProfileStore with Wally and start, use and end a session with its API
  • Explain how ProfileStore's session locking, autosave and steal timing differ from the hand-rolled 45-second lock
  • Migrate Beacon Yard's saved coins from the old record to a ProfileStore profile exactly once

Before this: DataStores: saving without losing a single coin

1Everything DataService does by hand

Open src/server/DataService.luau at m09-react-shop. It is about 389 lines. It loads with UpdateAsync, writes its own sessionJob and sessionAt lock, tries a failed save up to four times (1 initial try and 3 retries), saves everyone in BindToClose, and guards against saving over a failed load. It has no autosave, so a long session's lock looks expired after 45 seconds. You saw that gap in the last lesson.

Figure 1.1.

The hand-rolled version saving and loading. After the migration, a player must see the same coins.

Transcript
  1. 0:00 Coins increase in memory when you pick one up.
  2. 0:05 Stop ends the session and BindToClose saves if the key is savable.
  3. 0:10 The next Play loads the same coins.
  4. 0:20 GetAsync prints the row. The game writes it with UpdateAsync.
Figure 1.2

Which fields of the hand-rolled record exist only to implement the session lock?

  1. sessionJob
  2. sessionAt
  3. coins
  4. speedOwned
Answer

sessionJob; sessionAt. sessionJob and sessionAt are the sign-out sheet. coins and speedOwned are the player's data, the only part worth carrying into the new store.

Open this step in lesson mode · Link to this step · This confused me

2ProfileStore

ProfileStoreProfileStoreloleris's free module that loads a player's data once, locks it to one server and autosaves it.Think of it as a librarian who checks a file out to one desk at a time and files it back for you. is a free, open-source module by loleris (MAD STUDIO) that loads a player's data once, locks it to one server, autosaves it, and saves it a final time when you end the session1. It is a single ModuleScript under the Apache 2.0 licence, and its DevForum thread is active2. The data you work with is a plain table, profile.Data.

ProfileStore replaces the same author's ProfileService, whose README now says it is no longer supported and points new projects to ProfileStore3. If a tutorial says ProfileService, it is out of date.

Its README is also honest about what it is not for: it is built for one profile per player and is "not designed (and never will be) for in-game leaderboards or any kind of global state". Leaderboards get their own lesson.

Which of these jobs suit ProfileStore?

  1. A player's coins and upgrades
  2. A global top-100 coin leaderboard
  3. A matchmaking queue shared by all lobby servers
  4. A player's settings, such as music muted
Answer

A player's coins and upgrades; A player's settings, such as music muted. Per-player data is exactly what it is for. A leaderboard needs an OrderedDataStore, and a shared queue needs MemoryStore; both are read and written by many servers at once.

Open this step in lesson mode · Link to this step · This confused me

3Install it as a server package

ProfileStore is on Wally as lm-loleris/profilestore, and version 1.0.3 was the newest on 2026-11-231. Its realm is server, so it goes under [server-dependencies], and wally install puts it in a ServerPackages folder. Map that folder into ServerScriptService, where clients cannot see it.

toml
[server-dependencies]
ProfileStore = "lm-loleris/profilestore@1.0.3"
json
"ServerScriptService": {
  "Server": { "$path": "src/server" },
  "ServerPackages": { "$path": "ServerPackages" }
}
Go deeper What a realm is

Wally sorts packages into realms that say where they are meant to run: shared, server or dev. ProfileStore's own wally.toml declares realm = "server", so it installs under [server-dependencies] into a ServerPackages folder rather than Packages.

Why does ProfileStore live in ServerScriptService rather than ReplicatedStorage?

  1. It only runs on the server, and clients have no reason to see data-layer code
  2. Wally refuses to install it anywhere else
  3. ReplicatedStorage cannot hold ModuleScripts
  4. It makes ProfileStore save faster
Answer

It only runs on the server, and clients have no reason to see data-layer code. DataStores are server-only. Keeping server packages in ServerScriptService also means exploiters cannot read the code.

Open this step in lesson mode · Link to this step · This confused me

4Sessions: start, use, end

The whole API for a player is a handful of calls4:

Reference ProfileStore, the parts Beacon Yard uses

Async methods yield until they have a result; the rest return at once.

ProfileStore.New(storeName, template) -> store
Like GetDataStore. New profiles start as a deep copy of template.
store:StartSessionAsync(key, { Cancel = fn }?) -> Profile?
Loads the profile and locks it to this server. Waits if another server holds it. Returns nil in rare conflicts.
profile.Data
The plain table you read and change. Saved on the next autosave and on EndSession.
profile:Reconcile()
Fills in fields that exist in the template but not in Data.
profile:AddUserId(userId)
Tags the key with the player's id for data-deletion requests.
profile.OnSessionEnd:Connect(fn)
Fires when the session ends here, including when another server takes it.
profile:EndSession()
Final save and release. Always call it when the player leaves.
store.Mock
The same API on an in-memory store that is never saved.
luau
local store = ProfileStore.New("BeaconYard_v2", { coins = 0, speedOwned = false })
 
local profile = store:StartSessionAsync("Player_" .. player.UserId, {
	Cancel = function()
		return player.Parent ~= Players
	end,
})
if profile == nil then
	return -- no lock: the docs suggest player:Kick() here; Beacon Yard keeps the visit in memory and never saves it
end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile.OnSessionEnd:Connect(function()
	if player.Parent == Players then
		player:Kick("Your profile was opened on another server.")
	end
end)
	local session = playerStore:StartSessionAsync(profileKey(player.UserId), {
		Cancel = function()
			return player.Parent ~= Players
		end,
	})
Figure 4.1

That is the real call in Beacon Yard at m10-memory.

The nil case is rare, and the ProfileStore docs say to kick the player when it happens. Beacon Yard chooses differently: the player keeps playing on a fresh copy held only in memory, and nothing from that visit is ever saved. The cost is real. Everything the player earns in that visit is gone when they leave. In return, a rare hiccup does not end their session. A game that charges Robux should kick instead, so nothing a player paid for can vanish.

What is the Cancel function for?

  1. To stop waiting for the lock if the player leaves before the session starts
  2. To cancel the player's purchases
  3. To end the session after five minutes
  4. To skip the autosave
Answer

To stop waiting for the lock if the player leaves before the session starts. ProfileStore calls Cancel while it waits. Returning true tells it the player is gone, so it stops making DataStore requests for nobody.

Open this step in lesson mode · Link to this step · This confused me

5How ProfileStore holds the lock

ProfileStore keeps the lock inside its own record and renews it with an autosave every 300 seconds. When a second server asks for a key that is still held, ProfileStore asks the holder to save and let go, using MessagingService, then re-reads every few seconds. If the holder does not answer within about 40 seconds, the new server steals the session. A profile with no update for 630 seconds is assumed to belong to a crashed server5.

Stored dataRemember: Session lock is the vault sign-out sheet: Server A has this account, signed at 14:02.

Compare that with DataService: a 45-second window that nothing renews, and no way to ask the holder to hurry. ProfileStore's sheet is signed again on every autosave, and the waiting server can knock on the door.

Where does it break?“The vault sign-out sheet: Server A has this account, signed at 14:02” is a good picture of session lock. Where does it stop being true?

It breaks here. Nobody enforces the sheet; it only works because every server that touches the key checks it, and an unrenewed lock looks expired.

The true model. A session lock records which server holds a player's data so two servers do not write it at once. Beacon Yard's hand-rolled lock expires after 45 seconds so a crashed server cannot hold a key forever. ProfileStore renews its lock with an autosave every 300 seconds.

Even ProfileStore's sheet is only a convention. Nothing in the DataStore stops a server from ignoring it, and ProfileStore itself has an option that does exactly that: StartSessionAsync(key, { Steal = true }) takes the session without waiting for the holder's final save.

A teammate loads player data with StartSessionAsync(key, { Steal = true }) to make joins faster. What is wrong?

  1. Steal skips the lock, so a second server can load stale data and duplicate items
  2. Nothing; it is the recommended setting
  3. Steal deletes the profile
  4. Steal only works in Studio
Answer

Steal skips the lock, so a second server can load stale data and duplicate items. Steal bypasses the session lock that prevents dupes. The docs say to use it only for debugging, never for loading player data.

Open this step in lesson mode · Link to this step · This confused me

6Moving the old coins across, once

You cannot point ProfileStore at BeaconYard_v1. It stores its own structure (the data plus metadata such as the lock), and it treats any other table at a key as overwritten data, which it would replace. So the m10-memory milestone moves profiles to a new store, BeaconYard_v2, with keys like Player_123, and copies each player's old record across the first time they load.

The copy is a small pure module, DataMigration. A flag in the profile, legacyImported, makes sure it happens once. The rule: coins add up, speed is kept if either side has it.

Luau
local function apply(data, raw)
	if data.legacyImported then return false end
	data.legacyImported = true
	if typeof(raw) ~= "table" then return false end
	local coins = raw.coins
	if typeof(coins) == "number" and coins == coins and coins >= 0 and coins < math.huge then
		data.coins += math.floor(coins)
	end
	data.speedOwned = data.speedOwned or raw.speedOwned == true
	return true
end
 
local data = { coins = 0, speedOwned = false, legacyImported = false }
local old = { coins = 120, speedOwned = true, sessionJob = "abc", sessionAt = 1794542891 }
print(tostring(apply(data, old)) .. " " .. data.coins .. " " .. tostring(data.speedOwned))
print(tostring(apply(data, old)) .. " " .. data.coins)
Figure 6.1. Expected output: true 120 true false 120

Why does the second apply return false and leave 120 coins?

  1. legacyImported is already true, so the old record is never added twice
  2. The old record was deleted after the first call
  3. UpdateAsync refused the second write
  4. Coins cannot go above 120
Answer

legacyImported is already true, so the old record is never added twice. The flag lives in the profile and is saved with it. Without it, every login would add the old 120 coins again: a duplication bug.

Open this step in lesson mode · Link to this step · This confused me

7What studios actually use

Retiring the analogy

You no longer need “the vault sign-out sheet: server a has this account, signed at 14:02”. A session lock records which server holds a player's data so two servers do not write it at once. Beacon Yard's hand-rolled lock expires after 45 seconds so a crashed server cannot hold a key forever. ProfileStore renews its lock with an autosave every 300 seconds.

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
ProfileStoreSession-locked profiles with autosave, steal timing, Mock and a one-file install.The current default for per-player data in most new Roblox games.Its record format is its own, and it does not do leaderboards or shared state.
Hand-rolledYour own UpdateAsync, lock, autosave and retries, like Beacon Yard's DataService.Learning, or data that no library fits.Every edge case is yours to find, usually in production.
Suphi's DataStore ModuleAnother session-locking module, popular on the DevForum since 2023.Teams that prefer its API and its own documentation.A different author and conventions; compare the two before you commit.
ProfileService (legacy)ProfileStore's predecessor by the same author.Only in games that already use it.No longer supported; its README sends new projects to ProfileStore.
DataStore2 (legacy)An older caching wrapper.Maintaining old games.Last updated in 2023, no session lock.

You turned on Studio access to API services to test purchases. How do you stop Studio sessions from writing to real players' profiles?

  1. Use store.Mock when RunService:IsStudio() is true
  2. Turn off autosave
  3. Use a different place name
  4. ProfileStore never saves in Studio
Answer

Use store.Mock when RunService:IsStudio() is true. The ProfileStore docs show swapping in store.Mock in Studio. It never touches the DataStore, so tests cannot damage real data.

Open this step in lesson mode · Link to this step · This confused me

8Build along: the m10 migration

The m10-memory milestone is tagged, so you can compare your work with git diff m09-react-shop m10-memory.

  • wally.toml
  • default.project.json
  • src/shared/Config.luau
  • src/server/DataMigration.luau
  • src/server/DataService.luau
  1. Add ProfileStore under [server-dependencies] in wally.toml and run wally install.

    You should see ServerPackages/ProfileStore.lua exists and wally.lock lists lm-loleris/profilestore 1.0.3.

  2. Map ServerPackages into ServerScriptService in default.project.json, and add PROFILE_STORE_NAME = "BeaconYard_v2" to Config.

    You should see ServerScriptService.ServerPackages.ProfileStore appears in Explorer after Rojo syncs.

  3. Create src/server/DataMigration.luau with the template (coins, speedOwned, legacyImported) and the apply function from this lesson.

    You should see DataMigration.luau has template, readLegacy and apply, and requires nothing.

  4. Rewrite DataService around StartSessionAsync, Reconcile, OnSessionEnd and EndSession, call the migration once per session, and keep its public functions (addCoins, trySpend, save) the same so the rest of the game does not change.

    You should see On Play, a player with an old BeaconYard_v1 record sees the same coins, and the next Play does not add them again.

Open this step in lesson mode · Link to this step · This confused me

9Challenges

Level 2, Builder

Challenge

Make Studio sessions use ProfileStore's Mock so testing never writes real keys.

Start from
The game at milestone m10 (download)

Done means

  • In Studio, DataService uses the Mock store
  • In a live server it uses the real store
  • Output says which one is in use, once

Hints

  1. RunService:IsStudio()
  2. Swap the store before any session starts.
  3. Print once at start, not per player.

Level 3, Professional

Challenge

Add a saved field the ProfileStore way. Compare how many places you would have had to edit in the hand-rolled DataService. The test is challenges/profilestore.luau, and the solution is challenges/solutions/profilestore.md.

Start from
The game at milestone m10 (download)
Grade it
To grade work from an earlier milestone, apply your challenge changes to a checkout based on m14-ship, which includes the Course Runner. In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("profilestore", "profilestore-new-field") in the server command bar. Copy the pass code from Output.

Done means

  • The template holds dronesDowned = 0
  • Reconcile adds dronesDowned to a profile saved before the field existed
  • challenges/profilestore.luau prints TEST PASS for every check

Hints

  1. Add the field to the type and to DataMigration.template.
  2. Reconcile is already called after StartSessionAsync.
  3. The test uses the Mock store, so it runs in an unpublished place.

A player leaves server A and joins server B two seconds later. A is healthy and ending the session. What normally happens on B?

  1. B waits while A finishes its final save and releases, then loads the saved data
  2. B loads the old data at once and both servers save
  3. B kicks the player
  4. B waits the full 630 seconds
Answer

B waits while A finishes its final save and releases, then loads the saved data. A's EndSession saves and releases; B's re-read sees the released lock and loads the new data. Stealing after about 40 seconds and the 630-second dead check are for servers that never answer.

Open this step in lesson mode · Link to this step · This confused me

10Recap

Recap

  1. ProfileStore (lm-loleris/profilestore, a server package) is the current choice; ProfileService and DataStore2 are legacy.
  2. StartSessionAsync locks a profile to one server; autosave every 300 s renews it, a waiting server asks the holder to release and steals after about 40 s.
  3. ProfileStore needs its own store, so old records are copied once into BeaconYard_v2, guarded by a legacyImported flag.

Session lock is the vault sign-out sheet: Server A has this account, signed at 14:02, until nobody enforces the sheet; it only works because every server that touches the key checks it, and an unrenewed lock looks expired.

Next Leaderboards and badges

Open this step in lesson mode · Link to this step · This confused me