Hand-written by Joseph San Nicolas, Roblox Developer
SharedTable
Constructors
| Name | Description |
| new() | Returns a new, empty SharedTable. |
| new(t: table) | Returns a new SharedTable containing elements equivalent to those in the provided Luau table. Construction fails if the table contains a key that isn't a string or a nonnegative integer under 2^32, or a value that isn't a boolean, number, vector, string, SharedTable, or other serializable data type. |
Code Snippet
local SharedTableRegistry = game:GetService("SharedTableRegistry")
local playerScores = SharedTable.new({ Alice = 10, Bob = 20 })
SharedTableRegistry:SetSharedTable("PlayerScores", playerScores)
local previous = SharedTable.increment(playerScores, "Alice", 5)
print(previous, playerScores["Alice"], SharedTable.size(playerScores))
Methods
| Name | Parameters | Returns | Description |
| clear(st: SharedTable):() | st: SharedTable | () | Atomically removes all elements from a SharedTable. Raises an error if the SharedTable is frozen. |
| clone(st: SharedTable,deep: boolean?):SharedTable | st: SharedTable, deep: boolean? (default false) | SharedTable | Creates and returns a clone of the SharedTable. Shallow by default, or deep if deep is true. The returned clone is never frozen, even if the original was. |
| cloneAndFreeze(st: SharedTable,deep: boolean?):SharedTable | st: SharedTable, deep: boolean? (default false) | SharedTable | Creates and returns a frozen (read-only) clone of the SharedTable, using the same shallow/deep semantics as clone(). |
| increment(st: SharedTable,key: string | number,delta: number):number | st: SharedTable, key: string | number, delta: number | number | Atomically adds delta to the numeric value stored at key and returns the value it held immediately before the increment. |
| isFrozen(st: SharedTable):boolean | st: SharedTable | boolean | Returns true if the SharedTable is frozen (read-only). |
| size(st: SharedTable):number | st: SharedTable | number | Returns the number of elements stored in the SharedTable. |
| update(st: SharedTable,key: string | number,f: function):() | st: SharedTable, key: string | number, f: function | () | Atomically updates the element at key by calling f with its current value and storing the value f returns. f may be called more than once if the SharedTable is modified concurrently by other scripts. Raises an error if the SharedTable is frozen. |