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

How to use Find First Child?

I know how FindFirstChild works and all but say you did you had a part in workspace called part2

would you do game.Workspace:FindFirstChild(part2) OR game.Workspace:FindFirstChild("part2")

I forgot if you add a " or ' so yeah im confused also what do you also put or not put on waitforchild?

2 answers

✓ Accepted answer

FindFirstChild requires a string. This string is the name of the child you're looking for.

local part = workspace:FindFirstChild("Part")

If FindFirstChild doesn't find anything it will return nil. So if part doesn't exist in the above example, part will equal nil.

WaitForChild works about the same way, but it stops the script until it finds the child.

local part = workspace:WaitForChild("Part")

Now part will never equal nil, but if part doesn't exist the script will stop running. WaitForChild is normally used at the beginning of scripts, and used to wait for things that might not have loaded yet.

If I helped, please don't forget to accept my answer.

I recommend using

game.Workspace.Part2

2 comments

0

Why?

0

Well if you don't know how to use FindFirstChild:

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