SharedTable
Provides tables that can be shared between execution groups.
A table in every script's environment.
Behavior
SharedTable provides storage shared between ExecutionGroups in the current runtime.
Ordinary Luau tables remain local to their execution context.
Fields
clear · clone · cloneAndFreeze · increment · isFrozen · new · registry · size · toTable · update
clear
SharedTable.clear(table) removes all entries. Frozen tables reject writes.
clone
SharedTable.clone(table, deep?) copies shared storage. deep defaults to false; shallow copies retain references to nested shared tables.
cloneAndFreeze
SharedTable.cloneAndFreeze(table, deep?) creates a frozen copy. deep defaults to false.
increment
SharedTable.increment(table, key, delta) atomically adds delta to a numeric entry and returns the result.
isFrozen
SharedTable.isFrozen(table) returns whether writes to the table are prohibited.
new
SharedTable.new(initial?) creates shared storage from an optional Luau table. Keys must be strings or signed 64-bit integers. Values can include booleans, numbers, strings, buffers, supported value types, and nested shared tables. Functions, coroutines, Instances, and component handles are rejected. Conversion is limited to 32 nesting levels.
registry
SharedTable.registry(name) retrieves or creates named shared storage for the current place runtime. The name must be nonempty. Groups in that runtime can use the same name to access the same storage.
size
SharedTable.size(table) returns the number of stored entries.
toTable
SharedTable.toTable(table) returns an ordinary Luau table containing its entries. Nested shared tables remain shared values.
update
SharedTable.update(table, key, transform) atomically transforms an entry and returns the updated value. The callback receives the current value or nil. Keep the callback free of unrelated side effects because a concurrent update can require another attempt.
Example
local state = SharedTable.registry("scores")
SharedTable.increment(state, "visits", 1)