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:
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.
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
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 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