FindFirstChild (Function): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>GoldenUrg
Added link
>Anaminus
No edit summary
Line 3: Line 3:
name                  = FindFirstChild
name                  = FindFirstChild
|arguments            = [[String]] '''Name'''[, [[Bool]] '''recursive''']
|arguments            = [[String]] '''Name'''[, [[Bool]] '''recursive''']
|returns              = [[Instance]] ''found object''
|returns              = [[Instance]] ''child''
|description          = Returns the first child found with a name of '''Name'''. Returns ''nil'' if no such child exists.
|description          = Returns the first child found with a name of '''Name'''. Returns ''nil'' if no such child exists.
|object              = Global
|object              = [[Instance]]
}}</onlyinclude>
}}</onlyinclude>
|}
|}


==Example==
==Description==
{{Example|
<pre>
<pre>
--This looks in the Workspace for anything named "Brick",
local child = game.Workspace:FindFirstChild("Brick")   
-- and sets the variable "found" to whatever object it finds.
if child ~= nil then
-- if nothing is found, then found is nil.
    child:Remove()
found = Workspace:FindFirstChild("Brick")   
 
if found ~= nil then -- This makes sure that it actually found something.
  found.Name = "blah"  --Sets the object's name to "blah"
end
end
</pre>
</pre>
}}


==Recursive==
'''recursive''' is an optional argument that, when true, will cause FindFirstChild to check through the object's child, it's children's children, and so on.
The '''recursive''' argument is optional.
{{Example|
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.
'''Structure:'''
 
Workspace <!--this needs a better representation-->
For example, if there is a part in Workspace called "Part" and you use:
    Model
part = Game:FindFirstChild("Part", true)
        Part  
It will find the part.
<pre>
part = Game:FindFirstChild("Part", false)
local part = game.Workspace:FindFirstChild("Part")       -- returns nil
OR
local part = game.Workspace:FindFirstChild("Part",true-- returns Part
  part = Game:FindFirstChild("Part")
</pre>
Will not.
}}


==See Also==
==See Also==
[[Instance Hierarchy]]
[[Instance Hierarchy]]

Revision as of 22:56, 24 October 2010

FindFirstChild( String Name[, Bool recursive] )
Returns Instance child
Description: Returns the first child found with a name of Name. Returns nil if no such child exists.

Description

Example
local child = game.Workspace:FindFirstChild("Brick")  
if child ~= nil then
    child:Remove()
end


recursive is an optional argument that, when true, will cause FindFirstChild to check through the object's child, it's children's children, and so on.

Example
Structure:
Workspace 
    Model
        Part    
local part = game.Workspace:FindFirstChild("Part")       -- returns nil
local part = game.Workspace:FindFirstChild("Part",true)  -- returns Part


See Also

Instance Hierarchy