FindFirstChild (Method): Difference between revisions
From Legacy Roblox Wiki
Jump to navigationJump to search
m Text replacement - "</code>" to "</SyntaxHighlight>" |
m Text replacement - "</SyntaxHighlight>" to "</syntaxhighlight>" Tags: mobile web edit mobile edit |
||
Line 27: | Line 27: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local part = game:FindFirstChild("Part", true) | local part = game:FindFirstChild("Part", true) | ||
</ | </syntaxhighlight> | ||
}} | }} | ||
Line 34: | Line 34: | ||
local part = game:FindFirstChild("Part", false) | local part = game:FindFirstChild("Part", false) | ||
local part = game:FindFirstChild("Part") | local part = game:FindFirstChild("Part") | ||
</ | </syntaxhighlight> | ||
}} | }} | ||
[[Category:Methods]] | [[Category:Methods]] |
Latest revision as of 06:11, 27 April 2023
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")