BaseTableReplicator
Inherits from BaseObject.
Exposed Object Signals:
:GetSignal("ParentChanged")
:GetSignal("ChildAdded")
:GetSignal("ChildRemoved")
Types
Id
type
Id =
number
The id of a replicator.
SearchCondition
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
A signal that fires whenever a new replicator is created.
Functions
iterating over BaseTableReplicator
Metamethodfor
in
BaseTableReplicator
do
Iterates over all replicators that are currently in memory.
for _, replicator in TableReplicator do
print(replicator:GetServerId())
end
getFromServerId
StaticReturns the replicator with the given id if one exists.
forEach
StaticBaseTableReplicator.
forEach
(
allowDestroyedReplicators:
boolean?
) →
(
)
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
StaticBaseTableReplicator.
promiseFirstReplicator
(
allowDestroyedReplicators:
boolean?
) →
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
StaticFetches all replicators that are currently in memory. This is very slow and should be used sparingly.
listenForNewReplicator
StaticBaseTableReplicator.
listenForNewReplicator
(
) →
(
)
→
(
)
Listens for new replicators that are created with the given class token.
GetTableManager
Gets the TableManager that is being replicated.
GetServerId
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
Returns the parent of this replicator if it has one. If this replicator is a top level replicator then this will return nil.
GetChildren
Returns the immediate children of this replicator.
GetDescendants
Returns the descendants of this replicator.
FindFirstChild
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
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
(
tagKey:
string
) →
any
Returns the value of the given tag for this replicator.
GetTags
Returns the tags dictionary for this replicator.
IsSupersetOfTags
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
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