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

What's the difference between WaitForChild and FindFirstChild?

I'm a bit confused on each each of those means and what they're used for. Can anyone explain the differences of these two?

1 answer

✓ Accepted answer

FindFirstChild returns the child if it can find a child of the instance you call it on with a name equal to the string you provide.

local child = instance:FindFirstChild("ChildName")

If it can't find the child it returns nil

You can use instance.ChildName but this will error if ChildName is not a valid member of instance. To get around the error you use FindFirstChild with a if statement

local child = instance:FindFirstChild("ChildName")
if child then --ensures child is not nil
	print'child exists!'
end

WaitForChild yields until it can find a child of the instance you called it on with a name equal to the string you provide

local child = instance:WaitForChild("ChildName")
print'child now exists!'

This is used if you want to yield code until a child exists

3 comments

0

Wow, thanks for the help! I'll be able to use them a bit more, Thanks!

0

No problem :D

0

So Basics its in the name.

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