Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Does WaitForChild need to be used recursively?

Asked by
Speedmask 661 Moderation Voter
3 years ago

say I have a folder for remote events called "remotes" in ReplicatedStorage. if I wanted to access a remote, would I have to use

 ReplicatedStorage:WaitForChild("remotes"):WaitForChild("remote_event")

or is this redundant? does it only need to be used on one of these instances?
thanks.

0
I'd love to see more questions like these. radiant_Light203 1166 — 3y

3 answers

Log in to vote
4
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

If this folder would be inside of for example workspace then yes, you would have to do this, however, in your case, Yes, it is redundant, instances in ReplicatedStorage are replicated before local scripts run so there is no need for WaitForChild there, just index it with a dot. In Roblox parents are replicated first, then their children. On server you actually never have to use it because all Instances are replicated on the server, the only exception are things like new players, their UI for example, you might need WaitForChild there.

0
Is there a list which shows what loads first? It'd be helpful to prevent excessive :WaitForChild()ing. radiant_Light203 1166 — 3y
0
You mean something like this https://pastebin.com/U9680TUs ? WaitForChild does not wait for all descendants of Instance but just for the Instance itself so you will have to stack WaitForChilds unless you put all the stuff into ReplicatedStorage and then clone it from there, smart thing. imKirda 4491 — 3y
0
thank you. this dev wiki post was actually using waitforchild which is where I got the idea, I guess it wasn't necessary :) https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events Speedmask 661 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

It doesn't matter, although using WaitForChild recursively would be advisable because the remotes folder may load quicker than remote_event does, which will make an error in the script.

Log in to vote
0
Answered by 3 years ago

Only do

WaitForChild("Events").Remote_Event
0
hello, it seems like your answer conflicts with JBennett's answer where he said the folder could load before the remote, which is kind of what I was worrying about. do you wind telling me why I don't need WaitForChild on the second instance? thanks :) Speedmask 661 — 3y

Answer this question