FindFirstChild vs. WaitForChild

FindFirstChild simply finds the first thing with the given name of the first parameter. Usually you’d use this if you know 100% that the instance already exists when that line of code will run.

WaitForChild is different in the fact it will wait for something with the parameter name to exist. It won’t run the rest of the script until that actually exists. Useful if you’re unsure if the specific thing is there or spawned in or replicated quite yet.

Here is an example, as my explanation kinda sucks. Let’s say I have this script in the game.

task.wait(10)
local newPart = Instance.new("Part", workspace)

The script above will wait 10 seconds before spawning a part in workspace. If I have some code in another script which executes before this 10 second however, the following will occur:

workspace:FindFirstChild("Part") -- under the assumption this line fires before the part is replicated, this will error.

workspace:WaitForChild("Part") -- this will stop the script until it finds the part, thus waiting until the original line is fired.

Hopefully that helps. I left out a bit of information which can be found on the wiki page such as the other parameters, but I’m sure someone else can explain those more in depth if you’d like more info!

11 Likes