Skip to content

Shared Session Functions

Server-wide SharedSession state is separate from per-player profile data. It is not saved, is scoped to the current server, and syncs to all clients via a dedicated Replica. Configure defaults in PlayerStateConfig.Server.SharedSession (the table itself is the template—no nested Template key).

For concepts and examples, see Shared Session and Data visibility.

SetShared()

SetShared(key: string, value: any) → boolean

Sets a value at a top-level shared key only. If you need dot path syntax, use SetSharedPath.

Parameters: key: string, value: any
Returns: boolean — success


GetShared()

GetShared(key: string) → any

Gets a value by top-level key.

Parameters: key: string
Returns: any


SetSharedPath()

SetSharedPath(path: string, value: any) → boolean

Sets a value using dot notation (e.g. round.phase).

Parameters: path: string, value: any
Returns: boolean


GetSharedPath()

GetSharedPath(path: string) → any

Gets a value using dot notation.

Parameters: path: string
Returns: any


SetSharedValues()

SetSharedValues(values: { [string]: any }) → boolean

Applies multiple top-level key updates in one call.

Parameters: values — map of root key → value
Returns: boolean


OnSharedChanged()

OnSharedChanged(pathOrKey: string, callback) → Connection?

Subscribes to SharedSession changes on the server (same path rules as player OnChanged for key vs path).

Returns: Connection? — disconnect when done, or nil if invalid


GetSharedReplica()

GetSharedReplica() → ReplicaInstance?

Returns the raw SharedSession Replica for advanced use.

Returns: ReplicaInstance?


GetSharedAll()

GetSharedAll() → table?

Returns the full shared session data table when available.

Returns: table?


IsSharedReady()

IsSharedReady() → boolean

Whether the SharedSession Replica is ready for reads/writes.

Returns: boolean

Example
lua
PlayerState.SetSharedPath("round.phase", "Active")
PlayerState.SetSharedPath("round.endsAt", workspace:GetServerTimeNow() + 120)

PlayerState.OnSharedChanged("round.phase", function(newPhase)
    print("Phase:", newPhase)
end)

PlayerState - High-Performance Roblox Data Management