Saving player progress when two servers hold the same player


In Waterpark, players earn currency, ride counts and XP, raise pets, and set personal bests. All of it is saved to Roblox’s DataStore.

The naive save is SetAsync(key, currentData): write what this server has and overwrite what’s there. That works until a player is briefly on two servers at once, which happens every time they teleport or rejoin. The new server loads the record and the player keeps playing. Then the old server’s “player left” save arrives late and overwrites everything they did on the new server.

Nothing errors when this happens. The player just finds their progress rolled back.

A stamp and a remembered snapshot

The fix in DataManager.luau has two parts.

  • Every record carries a stamp that goes up by one on every write.
  • Every session remembers what it last read or wrote (seen): the stamp and the values at that point.

Saves go through UpdateAsync, which hands us the value currently stored (old) and lets us decide what to write:

if stamp == seen.stamp then
    -- nobody wrote since we last looked: write our values as they are
    record.gems = snap.gems
    ...
else
    -- another server wrote in between: add only what this session earned
    record.gems = math.max(0, num(old.gems) + snap.gems - seen.gems)
    ...
end
record.stamp = stamp + 1

If the stamp still matches, no other server has written, so we write our numbers. If it doesn’t match, another server got there first. Instead of overwriting, we add only the change this session made (now minus seen) on top of whatever is stored.

The new stamp is always the stored stamp plus one, so it never goes backwards. A late save from an old server can no longer erase newer progress.

Not every field can be added

Summing works for counters, but most fields need their own rule:

  • Personal bests, quest step, VIP expiry: take the larger value. Adding two “best tower floor” values makes no sense.
  • Best lap time: take the smaller value.
  • Daily login reward: the later date wins. If you added them, a player would get the same day twice.
  • Outfit and pets: these can’t be merged. If this session changed them, its version wins. Otherwise the stored version stays.

There are two more edge cases. If loading fails completely, the session’s seen.stamp is −1, which never matches a real record. That session will always add its own delta rather than overwrite, so a player whose load failed can keep playing without wiping the record they couldn’t read.

And during a deploy, an old build may still be running while a new build adds a field. Originally the save built a fresh record from the fields it knew about, so an old server would silently delete the new field. A code review on 2026-10-02 caught it. Now the save copies every stored field first and overwrites only the ones this build understands.

What it doesn’t do

The code comments say plainly that this is not a session lock. It guarantees that two servers holding the same player briefly won’t erase each other’s progress. It doesn’t make them a single owner.

There’s one known imperfection. If a save is reported as failed but actually succeeded, the retry can add the same delta twice. That only affects free in-game currency, so we accepted it rather than add a locking protocol with its own failure modes.

What we took away

  • “Last write wins” is a decision, and usually the wrong one for player data. Write down what should happen when two writers disagree, field by field.
  • Merge rules belong to the data, not the save function. Counters add, records take the max, choices take the latest edit.
  • Old code keeps running after you deploy. Any save format change has to survive the previous build writing to it.