Having trouble understanding FindFirstChild and WaitForChild

Hello there!

I’m not really understanding what FindFirstChild and WaitForChild are meant to do. If you can give me a response, that would be greatly appreciated!

A:FindFirstChild("Name") will return a child called Name inside of A, if it exists. If it doesn’t, it will return nil.

A:WaitForChild("Name") does the same thing, but instead of returning nil if the child doesn’t exist, it will pause the script until it does.

2 Likes

Thanks! I was just a little confused. It wasn’t clicking in my head at first but, this explanation has solved that issue. Thanks a lot!

Be careful with Object:WaitForChild("NameOfObject") because if you call it with a nonexistent object it may wait forever. You can do Object:WaitForChild("Name", n) to wait until it exists or n seconds have passed.
WaitForChild is primarily used to wait until objects are loaded in the game.
:slight_smile: Good luck!

2 Likes

Since other people already explained what they do, here’s a helpful article on when to use each:

3 Likes