Skip to content

Sync ​

Network-synchronized signals shared between the server and clients. Writes batch once per frame over a single RemoteEvent (or UnreliableRemoteEvent), and clients sync automatically on join.

luau
-- Shared
local round = Flux.Sync("Round", "Lobby")
local coins = Flux.Sync("Coins", 0)
local theme = Flux.Sync("Theme", "Dark", function(player, value)
	return value == "Dark" or value == "Light" -- clients may write it; the server validates
end)

-- Server
round("Fighting") -- every client
coins:of(player)(250) -- only that player

-- Client
Flux.new "TextLabel" { Text = function() return `{round()}: {coins()} coins` end }
theme("Light") -- optimistic; rolled back if the server rejects it

Types ​

Validator type ​

luau
type Validator<T> = (player: Player, value: T) -> (boolean?, ...T)

Validates a client write on the server (fn(player, value)). Return true to accept (true, replacement to store replacement), or false/nil to reject without yielding.

SyncSignal type ​

luau
type SyncSignal<T = any> = Graph.State<T> & {
	--[[
	Returns a per-player signal on the server whose writes replicate only to `player` (returns `self` on the client).
	]]
	of: (self: any, player: Player) -> Graph.State<T>,
	--[[
	Clears `player`'s per-player override on the server so they see the shared value again.
	]]
	clear: (self: any, player: Player) -> (),
	--[[
	Sets the server-side validator that allows clients to write to this signal (`nil` makes it server-only).
	]]
	validate: (self: any, fn: Validator<T>?) -> SyncSignal<T>,
	--[[
	Configures this signal to replicate over an `UnreliableRemoteEvent` instead of a reliable `RemoteEvent`.
	]]
	unreliable: (self: any, enabled: boolean?) -> SyncSignal<T>,
}

A signal synchronized between the server and clients. Server writes replicate to all clients, and client writes are validated on the server.

Namespace type ​

luau
type Namespace = {
	--[[
	Sends all pending synced changes immediately instead of waiting for the end of the frame.
	]]
	flush: () -> (),
	--[[
	Read-only node that is `true` on the server and turns `true` on the client once the initial sync arrives.
	]]
	ready: Graph.Node<boolean>,
	[string]: SyncSignal<any>,
} & (<T>(key: string, initial: T, validate: Validator<T>?) -> SyncSignal<T>)

Functions ​

flush ​

luau
Sync.flush()