Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Does WaitForChild need to be used recursively?

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.

1 comment

0

I'd love to see more questions like these.

3 answers

✓ Accepted answer

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.

3 comments

0

Is there a list which shows what loads first? It'd be helpful to prevent excessive :WaitForChild()ing.

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.

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

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.

Only do

WaitForChild("Events").Remote_Event

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.