FindFirstChild (Method)

From Legacy Roblox Wiki
Revision as of 06:11, 27 April 2023 by Realjame (talk | contribs) (Text replacement - "</SyntaxHighlight>" to "</syntaxhighlight>")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
FindFirstChild( string name, bool recursive = false )
Returns Instance
Description: 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.
Member of: Instance


Example
This looks in the Workspace for an object named "Brick". If found, it changes its name to "Foo":

local found = Workspace:FindFirstChild("Brick") if found then

 found.Name = "Foo"

end


Recursive

The recursive argument is optional. If given, recursive sets whether the function should look inside of objects in the calling object, as well as the calling object. If not given, the default is false.

For example, if there is a part in the Workspace called "Part".

Example
This will find the part.
local part = game:FindFirstChild("Part", true)


Example
These two solutions will not.
local part = game:FindFirstChild("Part", false)
local part = game:FindFirstChild("Part")