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

Step 1 of 10

Everything 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.

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.
Choose all that apply

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

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

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 2 of 10

ProfileStore

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.

Choose all that apply

Which of these jobs suit ProfileStore?

Which of these jobs suit ProfileStore?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 3 of 10

Install 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.

Choose one

Why does ProfileStore live in ServerScriptService rather than ReplicatedStorage?

Why does ProfileStore live in ServerScriptService rather than ReplicatedStorage?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 4 of 10

Sessions: 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,
	})

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.

Choose one

What is the Cancel function for?

What is the Cancel function for?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 5 of 10

How 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.

Choose one

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

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

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 6 of 10

Moving 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
Ctrl Enter runs the cell. Checked against the expected output
Choose one

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

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

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 7 of 10

What 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.
Choose one

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

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

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 8 of 10

Build 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.

Link to this step · This confused me

Step 9 of 10

Challenges

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

Meet the criteria above, then record your own result. No test grades this check.

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

The Course Runner prints this code when the test passes.

Choose one

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

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

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 10 of 10

Recap

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

Link to this step · This confused me