Skip to Content

Store

A named DataStore partition holding a set of persisted fields per player.

local stats = game:GetService("DataStore"):GetStore("Leaderstats")

Every method accepts a Player or a numeric user id. A user id gives access to data for players who are not connected.

Methods

Load

store:Load(player: Player | number): table

Yields until the player's data has loaded, then returns every field as a table.

Players.PlayerAdded:Connect(function(player)
	local saved = stats:Load(player)
	player:SetStat("Coins", saved.Coins or 0)
end)

Get

store:Get(player: Player | number, field: string): any

Returns the value of field, or nil.

Set

store:Set(player: Player | number, field: string, value: any)

Writes value to field.

Increment

store:Increment(player: Player | number, field: string, amount: number?): number

Adds amount (default 1) to a numeric field and returns the new value.

local coins = stats:Increment(player, "Coins", 1)
player:SetStat("Coins", coins)

Save

store:Save(player: Player | number, fields: table)

Writes several fields at once. Fields not present in fields are left unchanged.

Remove

store:Remove(player: Player | number, field: string)

Deletes field.

Clear

store:Clear(player: Player | number)

Deletes every field the player has in this store.

Properties

Name

store.Name: string

The name passed to GetStore.

On this page