Skip to content

Basic Data Functions ​

Set() ​

Set(player, key, value) → boolean

Sets a top-level data value with enhanced validation.

Parameters: player: Player, key: string, value: any
Returns: boolean - Success status (false if leaderstats modification attempted)

Example
lua
local success = PlayerState.Set(player, "Coins", 1000)
if success then
    print("Coins updated successfully")
else
    warn("Failed to update coins")
end

Note

Use SetPath() for nested paths instead of dot notation


Get() ​

Get(player, key) → any

Gets a top-level data value with validation. Automatically clones tables when AutoCloneTables is enabled in configuration.

Parameters: player: Player, key: string
Returns: any - The value, or nil if not found. Tables are cloned if AutoCloneTables is enabled.

Example
lua
local coins = PlayerState.Get(player, "Coins")
local level = PlayerState.Get(player, "Level")
print(`Player {player.Name} has {coins or 0} coins and is level {level or 1}`)

-- With AutoCloneTables enabled, tables are automatically cloned
local inventory = PlayerState.Get(player, "Inventory") -- Safe to modify
table.insert(inventory, newItem) -- Won't affect original if AutoCloneTables is true

Note

  • When AutoCloneTables is enabled in config, table values are automatically deep cloned
  • Prevents accidental modification of internal data structures
  • Configure in PlayerStateConfig.Server.AutoCloneTables

PlayerState - High-Performance Roblox Data Management