Skip to Content

State

Server-authoritative key-value table replicated to every client, with change events.

local State = game:GetService("State")

Values are written by the server and replicated to every client. Clients that join later receive the full current state on connect. Keys are strings. Values may be numbers, strings, booleans or Vector3.

Methods

Set

State:Set(key: string, value: any)

Writes value to key and replicates it to all clients. Server only.

State:Set("Status", "Waiting for players")
State:Set("TimeLeft", 90)

Get

State:Get(key: string): any

Returns the current value for key, or nil. Server and client.

Events

Changed

State.Changed(key: string, value: any)

Fires when a key's value changes. Server and client.

local UI = game:GetService("UI")
local panel = UI:CreatePanel({ Width = 220, Height = 40 })
local label = panel:AddLabel("", 18, true)

State.Changed:Connect(function(key, value)
	if key == "TimeLeft" then
		label.Text = "Time left: " .. value
	end
end)

On this page