Skip to main content

BaseTableReplicator

Inherits from BaseObject.

Exposed Object Signals:

:GetSignal("ParentChanged")
:GetSignal("ChildAdded")
:GetSignal("ChildRemoved")

Types

Id

type Id = number

The id of a replicator.

SearchCondition

type SearchCondition = string | ClassToken | Tags | (
replicatorBaseTableReplicator,
managerTableManager?
) → (boolean)

A condition that can be used to filter replicators. The condition can be a function, a ClassToken, a string representing a ClassToken's name, or a Tags dictionary.

  • If the condition is a function then it should return a boolean to indicate success.
  • If the condition is a ClassToken then it will check if the replicator's class token matches the given token.
  • If the condition is a string then it will check if the replicator's class token name matches the given string.
  • If the condition is a Tags dictionary then it will check if the replicator's tags are a superset of the given tags.

Tags

type Tags = {[string]any}

The valid tag format that can be given to a TableReplicator. This table will become locked once given to a TableReplicator. Do not attempt to modify it after the fact.

local tags = table.freeze {
    OwnerId = Player.UserId;
    ToolType = "Sword";
}

Properties

ReplicatorCreated

BaseTableReplicator.ReplicatorCreated: Signal<BaseTableReplicator>

A signal that fires whenever a new replicator is created.

Functions

iterating over BaseTableReplicator

Metamethod
for   in  BaseTableReplicator  do

Iterates over all replicators that are currently in memory.

for _, replicator in TableReplicator do
    print(replicator:GetServerId())
end

getFromServerId

Static
BaseTableReplicator.getFromServerId(idId) → BaseTableReplicator?

Returns the replicator with the given id if one exists.

forEach

Static
BaseTableReplicator.forEach(
conditionSearchCondition,
fn(
replicatorBaseTableReplicator,
managerTableManager?
) → (),
allowDestroyedReplicatorsboolean?
) → ()

forEach is a special function that allows you to run a function on all replicators that currently exist or will exist that match the given condition.

caution

There are rare edge cases where if a Replicator is destroyed soon after it is created and you have deffered events, it will be destroyed before the ReplicatorCreated signal fires. In this case you can set allowDestroyedReplicators to true to allow destroyed replicators to be returned.

promiseFirstReplicator

Static
BaseTableReplicator.promiseFirstReplicator(
conditionSearchCondition,
allowDestroyedReplicatorsboolean?
) → Promise<BaseTableReplicator,TableManager?>

promiseFirstReplicator is a special function that allows you to run a function on the first replicator to satisfy the given condition. If no replicator currently exists that satisfies the condition then it will wait for one to be created.

caution

There are rare edge cases where if a Replicator is destroyed soon after it is created and you have deffered events, it will be destroyed before the ReplicatorCreated signal fires. In this case you can set allowDestroyedReplicators to true to allow destroyed replicators to be returned.

BaseTableReplicator.promiseFirstReplicator("Test")

getAll

Static
BaseTableReplicator.getAll(classTokenNamestring?) → {BaseTableReplicator}

Fetches all replicators that are currently in memory. This is very slow and should be used sparingly.

listenForNewReplicator

Static
BaseTableReplicator.listenForNewReplicator(
classTokenCanBeArray<string | ClassToken>,
fn(replicatorBaseTableReplicator) → ()
) → () → ()

Listens for new replicators that are created with the given class token.

GetTableManager

BaseTableReplicator:GetTableManager() → TableManager

Gets the TableManager that is being replicated.

GetServerId

BaseTableReplicator:GetServerId() → Id

Returns the server id for this replicator. On the Server this is equivalent to :GetId()

GetTokenName

BaseTableReplicator:GetTokenName() → string

Fetches the name of the class token that this replicator is using.

IsTopLevel

BaseTableReplicator:IsTopLevel() → boolean

Returns whether or not this replicator is a top level replicator. A top level replicator is a replicator that has no parent. Only top level replicators can have their ReplicationTargets set.

GetParent

BaseTableReplicator:GetParent() → BaseTableReplicator?

Returns the parent of this replicator if it has one. If this replicator is a top level replicator then this will return nil.

GetChildren

BaseTableReplicator:GetChildren() → {BaseTableReplicator}

Returns the immediate children of this replicator.

GetDescendants

BaseTableReplicator:GetDescendants() → {BaseTableReplicator}

Returns the descendants of this replicator.

FindFirstChild

BaseTableReplicator:FindFirstChild(
conditionSearchCondition,
recursiveboolean?
) → BaseTableReplicator?

Finds the first child that satisfies the given condition. The condition can be a function, a ClassToken, a string representing a ClassToken's name, or a Tags dictionary. If recursive is true then it will search through all descendants.

local child = tr:FindFirstChild(function(child)
    local manager = child:GetTableManager()
    return manager:Get("Test") == 1
})

PromiseFirstChild

BaseTableReplicator:PromiseFirstChild(conditionSearchCondition) → Promise<BaseTableReplicator>

Returns a promise that resolves when the first child that satisfies the given function is found.

tr:PromiseFirstChild(function(replicator)
    local manager = replicator:GetTableManager()
    return manager:Get("Test") == 1
}):andThen(function(replicator)
    print("Found child with data key 'Test' equal to 1!")
end)

tr:PromiseFirstChild("Test"):andThen(function(replicator)
    print("Found child with classtoken 'Test'!")
end)

tr:PromiseFirstChild({UserId == 12345}):andThen(function(replicator)
    print("Found child with UserId Tag matching 12345!")
end)

GetTag

BaseTableReplicator:GetTag(tagKeystring) → any

Returns the value of the given tag for this replicator.

GetTags

BaseTableReplicator:GetTags() → Tags

Returns the tags dictionary for this replicator.

IsSupersetOfTags

BaseTableReplicator:IsSupersetOfTags(tagsTags) → boolean

Checks whether or not the given tags are a subset of this replicator's tags. ELI5: Are all the given tags also on this replicator? Aliased as :ContainsAllTags(tags)

```lua

local tr = TableReplicator.new({ Tags = { Test1 = 1, Test2 = 2, } })

tr:IsSupersetOfTags({ Test1 = 1, }) -- true

tr:IsSupersetOfTags({ Test2 = 2, }) -- true

IsSubsetOfTags

BaseTableReplicator:IsSubsetOfTags(tagsTags) → boolean

Checks whether or not this replicator's tags are a subset of the given tags. ELI5: Are all the tags on this replicator also on the given tags? Aliased as :IsWithinTags(tags)

local tr = TableReplicator.new({
    Tags = {
        Test1 = 1,
        Test2 = 2,
    }
})

tr:IsSubsetOfTags({
    Test1 = 1,
    Test2 = 2,
    Test3 = 3,
}) -- true

tr:IsSubsetOfTags({
    Test1 = 1,
}) -- false
Show raw api
{
    "functions": [
        {
            "name": "__iter",
            "desc": "Iterates over all replicators that are currently in memory.\n```lua\nfor _, replicator in TableReplicator do\n    print(replicator:GetServerId())\nend\n```",
            "params": [],
            "returns": [],
            "function_type": "static",
            "tags": [
                "Metamethod"
            ],
            "source": {
                "line": 81,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "getFromServerId",
            "desc": "Returns the replicator with the given id if one exists.",
            "params": [
                {
                    "name": "id",
                    "desc": "",
                    "lua_type": "Id"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BaseTableReplicator?\n"
                }
            ],
            "function_type": "static",
            "tags": [
                "Static"
            ],
            "source": {
                "line": 153,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "forEach",
            "desc": "forEach is a special function that allows you to run a function on all replicators that currently\nexist or will exist that match the given condition.\n\n:::caution\nThere are rare edge cases where if a Replicator is destroyed soon after it is created and you have deffered events,\nit will be destroyed before the ReplicatorCreated signal fires. In this case you can set allowDestroyedReplicators to true\nto allow destroyed replicators to be returned.\n:::",
            "params": [
                {
                    "name": "condition",
                    "desc": "",
                    "lua_type": "SearchCondition"
                },
                {
                    "name": "fn",
                    "desc": "",
                    "lua_type": "(replicator: BaseTableReplicator, manager: TableManager?) -> ()"
                },
                {
                    "name": "allowDestroyedReplicators",
                    "desc": "",
                    "lua_type": "boolean?\n"
                }
            ],
            "returns": [],
            "function_type": "static",
            "tags": [
                "Static"
            ],
            "source": {
                "line": 172,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "promiseFirstReplicator",
            "desc": "promiseFirstReplicator is a special function that allows you to run a function on the first replicator to satisfy\nthe given condition. If no replicator currently exists that satisfies the condition then it will wait for one to be created.\n\n:::caution\nThere are rare edge cases where if a Replicator is destroyed soon after it is created and you have deffered events,\nit will be destroyed before the ReplicatorCreated signal fires. In this case you can set allowDestroyedReplicators to true\nto allow destroyed replicators to be returned.\n:::\n\n```lua\nBaseTableReplicator.promiseFirstReplicator(\"Test\")\n```",
            "params": [
                {
                    "name": "condition",
                    "desc": "",
                    "lua_type": "SearchCondition"
                },
                {
                    "name": "allowDestroyedReplicators",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<BaseTableReplicator, TableManager?>"
                }
            ],
            "function_type": "static",
            "tags": [
                "Static"
            ],
            "source": {
                "line": 225,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "getAll",
            "desc": "Fetches all replicators that are currently in memory. This is very slow and should be used sparingly.",
            "params": [
                {
                    "name": "classTokenName",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{BaseTableReplicator}\n"
                }
            ],
            "function_type": "static",
            "tags": [
                "Static"
            ],
            "source": {
                "line": 258,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "listenForNewReplicator",
            "desc": "Listens for new replicators that are created with the given class token.",
            "params": [
                {
                    "name": "classToken",
                    "desc": "",
                    "lua_type": "CanBeArray<string | ClassToken>"
                },
                {
                    "name": "fn",
                    "desc": "",
                    "lua_type": "(replicator: BaseTableReplicator) -> ()"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "() -> ()"
                }
            ],
            "function_type": "static",
            "tags": [
                "Static"
            ],
            "source": {
                "line": 272,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "new",
            "desc": "",
            "params": [
                {
                    "name": "config",
                    "desc": "",
                    "lua_type": "{\n    ServerId: Id?;\n    Tags: Tags?;\n    TableManager: TableManager;\n    IsTopLevel: boolean?;\n}"
                }
            ],
            "returns": [],
            "function_type": "static",
            "tags": [
                "Static"
            ],
            "private": true,
            "source": {
                "line": 303,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "",
            "params": [],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 341,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "_FireCreationListeners",
            "desc": "Fires the creation listeners for this replicator.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 355,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "GetTableManager",
            "desc": "Gets the TableManager that is being replicated.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "TableManager\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 382,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "GetServerId",
            "desc": "Returns the server id for this replicator.\nOn the Server this is equivalent to :GetId()",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Id\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 390,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "GetTokenName",
            "desc": "Fetches the name of the class token that this replicator is using.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 397,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "IsTopLevel",
            "desc": "Returns whether or not this replicator is a top level replicator.\nA top level replicator is a replicator that has no parent.\nOnly top level replicators can have their ReplicationTargets set.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 406,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "GetParent",
            "desc": "Returns the parent of this replicator if it has one.\nIf this replicator is a top level replicator then this will return nil.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BaseTableReplicator?\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 419,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "GetChildren",
            "desc": "Returns the immediate children of this replicator.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{BaseTableReplicator}\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 426,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "GetDescendants",
            "desc": "Returns the descendants of this replicator.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{BaseTableReplicator}\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 433,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "FindFirstChild",
            "desc": "Finds the first child that satisfies the given condition.\nThe condition can be a `function`, a `ClassToken`, a `string` representing a ClassToken's name, or a `Tags` dictionary.\nIf recursive is true then it will search through all descendants.\n```lua\nlocal child = tr:FindFirstChild(function(child)\n    local manager = child:GetTableManager()\n    return manager:Get(\"Test\") == 1\n})\n```",
            "params": [
                {
                    "name": "condition",
                    "desc": "",
                    "lua_type": "SearchCondition"
                },
                {
                    "name": "recursive",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "BaseTableReplicator?\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 458,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "PromiseFirstChild",
            "desc": "Returns a promise that resolves when the first child that satisfies the given function is found.\n\n```lua\ntr:PromiseFirstChild(function(replicator)\n    local manager = replicator:GetTableManager()\n    return manager:Get(\"Test\") == 1\n}):andThen(function(replicator)\n    print(\"Found child with data key 'Test' equal to 1!\")\nend)\n\ntr:PromiseFirstChild(\"Test\"):andThen(function(replicator)\n    print(\"Found child with classtoken 'Test'!\")\nend)\n\ntr:PromiseFirstChild({UserId == 12345}):andThen(function(replicator)\n    print(\"Found child with UserId Tag matching 12345!\")\nend)\n```",
            "params": [
                {
                    "name": "condition",
                    "desc": "",
                    "lua_type": "SearchCondition"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<BaseTableReplicator>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 500,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "GetTag",
            "desc": "Returns the value of the given tag for this replicator.",
            "params": [
                {
                    "name": "tagKey",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 519,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "GetTags",
            "desc": "Returns the tags dictionary for this replicator.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Tags\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 526,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "IsSupersetOfTags",
            "desc": "Checks whether or not the given tags are a subset of this replicator's tags.\nELI5: Are all the given tags also on this replicator?\nAliased as `:ContainsAllTags(tags)`\n    ```lua\nlocal tr = TableReplicator.new({\n    Tags = {\n        Test1 = 1,\n        Test2 = 2,\n    }\n})\n\ntr:IsSupersetOfTags({\n    Test1 = 1,\n}) -- true\n\ntr:IsSupersetOfTags({\n    Test2 = 2,\n}) -- true\n```",
            "params": [
                {
                    "name": "tags",
                    "desc": "",
                    "lua_type": "Tags"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 551,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "IsSubsetOfTags",
            "desc": "Checks whether or not this replicator's tags are a subset of the given tags.\nELI5: Are all the tags on this replicator also on the given tags?\nAliased as `:IsWithinTags(tags)`\n```lua\nlocal tr = TableReplicator.new({\n    Tags = {\n        Test1 = 1,\n        Test2 = 2,\n    }\n})\n\ntr:IsSubsetOfTags({\n    Test1 = 1,\n    Test2 = 2,\n    Test3 = 3,\n}) -- true\n\ntr:IsSubsetOfTags({\n    Test1 = 1,\n}) -- false\n```",
            "params": [
                {
                    "name": "tags",
                    "desc": "",
                    "lua_type": "Tags"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 585,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "ReplicatorCreated",
            "desc": "A signal that fires whenever a new replicator is created.",
            "lua_type": "Signal<BaseTableReplicator>",
            "source": {
                "line": 91,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        }
    ],
    "types": [
        {
            "name": "Id",
            "desc": "The id of a replicator.",
            "lua_type": "number",
            "source": {
                "line": 46,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "SearchCondition",
            "desc": "A condition that can be used to filter replicators.\nThe condition can be a `function`, a `ClassToken`, a `string` representing a ClassToken's name, or a `Tags` dictionary.\n- If the condition is a function then it should return a boolean to indicate success.\n- If the condition is a ClassToken then it will check if the replicator's class token matches the given token.\n- If the condition is a string then it will check if the replicator's class token name matches the given string.\n- If the condition is a Tags dictionary then it will check if the replicator's tags are a superset of the given tags.",
            "lua_type": "string | ClassToken | Tags | (replicator: BaseTableReplicator, manager: TableManager?) -> (boolean)",
            "source": {
                "line": 108,
                "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
            }
        },
        {
            "name": "Tags",
            "desc": "The valid tag format that can be given to a TableReplicator.\nThis table will become locked once given to a TableReplicator.\nDo not attempt to modify it after the fact.\n```lua\nlocal tags = table.freeze {\n    OwnerId = Player.UserId;\n    ToolType = \"Sword\";\n}\n```",
            "lua_type": "{[string]: any}",
            "source": {
                "line": 26,
                "path": "src/tablereplicator/src/Shared/TableReplicatorUtil.lua"
            }
        }
    ],
    "name": "BaseTableReplicator",
    "desc": "Inherits from BaseObject.\n\nExposed Object Signals:\n```lua\n:GetSignal(\"ParentChanged\")\n:GetSignal(\"ChildAdded\")\n:GetSignal(\"ChildRemoved\")\n```",
    "source": {
        "line": 15,
        "path": "src/tablereplicator/src/Shared/BaseTableReplicator.lua"
    }
}