What does the function WaitForChild do?

I’m still a noobie, and learning every step of the way. Any help would be great.

WaitForChild simply does what it says, it waits for a child of a certain name of a specific instance to exist before continuing, it has 2 arguments, the name of the child to wait for, and the time it waits for it to exist before stopping and returning nil

Take this for example

local part = workspace:WaitForChild("Part")

This will wait until a child called “Part” is added into workspace and returns that into the variable, but if you have nothing called Part in workspace and nothing adds a part, it will yield infinitely, to solve that, add a TimeOut

local part = workspace:WaitForChild("Part",5)

This will wait for the child to exist and if it still doesn’t exist after 5 seconds, it will return nil into the variable and continue on in the script

2 Likes