Help with Content replication logic

I want to know if using “WaitForChild” on a folder or model will ensure its children have been replicated too when the parent is done or i need to do “WaitForChild” for each of its children.

I will explain below with an example:

Lets say i have a folder in the ReplicatedSorage like this:

defaultFolderwithModels

Version 1 - Is it safe to use like this?:

-- LocalScript
local folder = game:GetService("ReplicatedStorage"):WaitForChild("Folder")

local _modelA = folder.ModelA
local _modelB = folder.ModelB
local _modelC = folder.ModelB

Version 2 - or i must use this?:

-- LocalScript
local folder = game:GetService("ReplicatedStorage"):WaitForChild("Folder")

local _modelA = folder:WaitForChild("ModelA")
local _modelB = folder:WaitForChild("ModelB")
local _modelC = folder:WaitForChild("ModelB")

Thank you

Edit: The question is: after waiting for the Folder, is it guaranteed that the contents of it are loaded too?

Version 2 is definitely better. But if the top folder loads, most likely the children have loaded too.
But I would use the 2nd option if possible as it is safer and prevents an error if the children aren’t replicated immediately.

I use the 2, but was wondering if it is redundant and i can use the faster 1 method
Thank you for reply,

1 Like

It depends on how important this is, and if you really need the extra speed.

Variation 1, as if you do this following snippet below above all your existing code, then everything in ReplicatedStorage has loaded (then there would not be the need to do variation 2):

if (not game:IsLoaded()) then
    game.Loaded:Wait()
end

e.g

if (not game:IsLoaded()) then
    game.Loaded:Wait()
end

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local something = ReplicatedStorage.something -- works as game has loaded already and everything has been replicated from ReplicatedStorage to Client
1 Like

I just want to understand how it works as i can’t find this explicit case anywhere

I understand this, thank you for your reply, but this does not answer my question though. I want to understand how the “WaitForChild” actually works: it is waiting for all its childs first to be loaded or just that file and children will be loaded later…

WaitForChild is what it says: waiting for the child to be loaded.

WaitForChild Waits For an Object, if it can find it the object, it will continue waiting until it exists
Which is why it warns:
Ininite yield Possible For...

Version 1 can be Used better, but its dependent on how fast the Objects loads in
(Typically a LocalScript, but sometimes a Regular Script)

However Version 2 can also be used better due to actually Waiting instead if Finding the Object right away

1 Like

After waiting for the Folder, is it guaranteed that the contents of it are loaded too?

Ususally, it has to load the Folder, and then its Contents.

Its Waiting for the Object, and that object has children in it

From below image i thought that the folder or model tree is sent first and any baseparts inside the model can take longer.


Image from Content Streaming | Roblox Creator Documentation

So i thought that you can get the models without wating on them but for baseparts that might be inside model i know it needs waitforchild.

Think of It like this:

workspace:WaitForChild("Part").Attachment
-- It Waits For The Object, then Looks for the Children

Sometimes, this wont work, i have seen some people do this:

workspace:WaitForChild("Part"):WaitForChild("Attachment")

No, it is not guaranteed that the contents of it are loaded too.
Check this post also.

thank you, i was looking for this but i could not find it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.