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