Skip to content
Untitled Sandbox - Developer Documentation
docs/types/PlayerState

PlayerState<T>

A value that is kept separately for each player and tells you when it changes, which you create with state.create_per_player.

Events

changedEvent<(Player, T, T)>

You listen to these with :connect, which the Event page covers.

PlayerState:get

method

Gives a copy of one player's value, which still works for 5 seconds after they leave.

PlayerState:get(player: Player) -> T
example
print(coins:get(player))

Use it forchecking whether a player has enough tokens to buy an item in your shop.

playerThe player.

PlayerState:set

method

Changes one player's value, and is an error once that player has left.

PlayerState:set(player: Player, value: T) -> ()
example
coins:set(player, 0)

Use it forresetting a player's checkpoint when they restart the obby from the beginning.

playerThe player.
valueThe new value.

PlayerState:update

method

Hands your function one player's value, and saves whatever it gives back.

PlayerState:update(player: Player, update: (T) -> T) -> ()
example
coins:update(player, function(value) return value + 1 end)

Use it foradding an item to a player's inventory list without replacing what they already have.

playerThe player.
updateGets the value and returns the new one.

PlayerState:increment

method

Adds to one player's number value, or takes away, and gives back the new value.

PlayerState:increment(player: Player, amount: number?) -> number
example
coins:increment(player, 10)

Use it forgiving a player tokens when they pick one up, or taking them away when they buy something.

playerThe player.
amountoptionalHow much to add, 1 by default. A negative amount takes away.
↑ ↓ moveEnter openEsc close