Ledger

Overview

Ledger saves Roblox player data safely. Every change is saved once, and every answer tells you what happened.

Ledger is a DataStore library for Roblox. You describe how your data is allowed to change, and Ledger saves each change exactly once, even when a server crashes or two servers change the same player at the same moment.

local Ok, Why = PlayerStore:Edit(Player.UserId, { Kind = "AddGold", Amount = 50 })
if not Ok then
	warn("Couldn't add gold:", Why)
end

true means the change is saved. Anything else is a reason that says what happened, and Answers says what to do about each one.

What it's for

JobWhat you get
Player dataLoaded when they join, saved while they play and when they leave.
Developer productsA purchase is granted once, even when Roblox sends the receipt again.
TradesBoth players change, or neither does, across servers and offline.
Guild banks and shopsData many servers change at once, without losing a change.
Auctions and marketsGold held safely until the auction ends or the item sells.
Limited itemsA fixed number sold across every server, never one too many.
Global countersA number every server adds to, like total boss kills.
UpdatesChange the shape of your data without breaking old saves.
Deleting dataErase a player's data when Roblox asks you to.

What it isn't for

  • Client scripts. Ledger runs on the server. Calling it from a client throws.
  • Searching. You can't search your data. Store:Keys() lists every key, or the keys that start with a prefix, a page at a time.
  • History. Ledger keeps no log of what changed. Roblox keeps a version of a player's data for each hour it was written, for 30 days: Store:Versions(Key) lists them and Store:PeekVersion(Key, Version) reads one.

Where to start

The Learn pages build one game in order, starting with saving a player's gold. Each page adds one thing, and every sample is complete and type-checked. Start at the top and read them in order.

Next: Getting started

On this page