I've been having problems with WaitForChild in a couple of my scripts, which makes me think maybe I've misunderstood how it works. On the wiki it says "If the child does not exist, it will yield the current thread until it does."
Does this mean it pauses the entire script on that line until the object mentioned is loaded, or simply that the variable won't be assigned until the object is loaded?
I've been using it in the former context, trying to make my whole script wait until other scripts have loaded (to make sure required global variables are defined) but it hasn't been working.
Just wanna check this point before I troubleshoot any further.
Thanks!
You said it yourself - it will yield the current thread (in your case, the entire script unless you're using spawn
or coroutine
s) until the child exists. You can test this pretty easily with some code in the command line:
game:WaitForChild("hey I don't exist") print("g") -- this should never print