My problem is that my game clones different chunks of map on server-side. And After cloning all of the chunks server calls client event to add some listeners on client side. Heres an example of that:
output(the result of GetChildren() ):
workspace(client side):
the problem is getChildren() doesn’t return all instances of parent…
here’s the client code:
local Component = require(Core.ReplicatedLibraries.Component)
for _, chunkName in pairs(arrayGeneratedChunkNames) do
local chunk = workspace.Map.Stages:FindFirstChild(chunkName)
print(chunk)
print(chunk.Assets:GetChildren())
for _, v in pairs(chunk.Assets:GetChildren()) do
--print(v)
local ComponentName = v:GetAttribute("Component")
if not ComponentName then
continue
end
--print(("%* %*"):format(v, ComponentName))
Component.Apply(v,ComponentName)
end
end
Also the fact if there’s some wait functions in iteration then GetChildren() will be executed as expected to be, now here’s the code how it’d look like with wait functions:
local Component = require(Core.ReplicatedLibraries.Component)
for _, chunkName in pairs(arrayGeneratedChunkNames) do
task.wait(1)
local chunk = workspace.Map.Stages:FindFirstChild(chunkName)
print(chunk)
print(chunk.Assets:GetChildren())
for _, v in pairs(chunk.Assets:GetChildren()) do
--print(v)
local ComponentName = v:GetAttribute("Component")
if not ComponentName then
continue
end
--print(("%* %*"):format(v, ComponentName))
Component.Apply(v,ComponentName)
end
end
local Component = require(Core.ReplicatedLibraries.Component)
for _, chunkName in pairs(arrayGeneratedChunkNames) do
local chunk = workspace.Map.Stages:FindFirstChild(chunkName)
print(chunk.Assets:GetFullName())
print(chunk.Assets:GetChildren())
for _, v in pairs(chunk.Assets:GetChildren()) do
--print(v)
local ComponentName = v:GetAttribute("Component")
if not ComponentName then
continue
end
--print(("%* %*"):format(v, ComponentName))
Component.Apply(v,ComponentName)
end
end
as i said its generated by server-side script
heres the code:
local MapGeneratorService = require(Core.ServerServices.MapGeneratorService)
local arrayGeneratedChunkNames = MapGeneratorService.GenerateChunks() -- this function generates map
for _, chunkName in pairs(arrayGeneratedChunkNames) do
local chunk = workspace.Map.Stages:FindFirstChild(chunkName)
for _, v in pairs(chunk.Assets:GetChildren()) do
local ComponentName = v:GetAttribute("Component")
if not ComponentName then
continue
end
Component.Apply(v,ComponentName)
end
end
task.wait()
local ComponentReplicator = require(Core.ReplicatedServices.ComponentReplicatorService)
ComponentReplicator:Replicate(arrayGeneratedChunkNames) -- call client-side script
So what happens if you add a huge delay(for testing) on the client sided code after the client script is triggered. Im assuming this is an issue with some sort of delay.
Okay then that means it’s not a fault of get children. What you should do is send a number that represents how many parts should be in a chunk, and then on the client you should wait until the amount of detected parts equals that. Of course, add a max wait time, and if it exceeds that, then send a message to the server for a retry.