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

What is the difference between 'FindFirstChild("String") and 'FindFirstChild("String",true)?

Asked by 10 years ago

I have seen this in different scripts, and have been using this myself, but I do not know what the difference between the two is, one is just one string, the other has a string and a boolean value, what do they both do?

2 answers

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
10 years ago

If the second argument of FindFirstChild is false or nil, it will only search for the child directly inside the object. However, if the second argument is true, it will search through all descendants by using recursion.

For example, if an object's heirarchy looks like this: game.Workspace.Part.Script, you can find the script by doing Workspace:FindFirstChild("Script",true), even though it's not directly under the Workspace.

Ad
Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

Returns the first child found with a name of name. Returns nil if no such child exists. If the optional recursive argument is true, will recursively descend the hierarchy while searching rather than only searching the immediate object. ~ ROBLOX Wiki

This has been a tip of the day on scripting helpers many times, and from my understanding it will search through descendants of descendants such as workspace to find a object with a name matching the string value. So I think if I wanted to destroy a selection box named bob inside a brick which was inside of workspace, then I would use;

workspace:FindFirstChild("bob", true):Destroy()

This is my understanding of it, but I have not tested it.

Answer this question