Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to use Find First Child?

Asked by 8 years ago

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

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

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.
Ad
Log in to vote
0
Answered by
skyab12 25
8 years ago

I recommend using

game.Workspace.Part2

0
Why? User#11440 120 — 8y
0
Well if you don't know how to use FindFirstChild: skyab12 25 — 8y

Answer this question