FindFirstChild (Function): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mr Doom Bringer
No edit summary
>GoldenUrg
fixed layout; added examples
Line 1: Line 1:
<onlyinclude>
{|
{{Function|
|<onlyinclude>{{Function|
name                  = FindFirstChild
name                  = FindFirstChild
|arguments            = [[String]] Name, [[Bool]] recursive
|arguments            = [[String]] '''Name'''[, [[Bool]] '''recursive''']
|returns              = [[Instance]] ''found object''
|returns              = [[Instance]] ''found object''
|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              = Global
}}
}}</onlyinclude>
</onlyinclude>
|}
 


==Example==
==Example==
<pre>
<pre>
--This looks in the Workspace for anything named "Brick",
-- and sets the variable "found" to whatever object it finds.
-- if nothing is found, then found is nil.
found = Workspace:FindFirstChild("Brick") 


while true do  --Starts up a While loop
if found ~= nil then  -- This makes sure that it actually found something.  
  found = game.Workspace:FindFirstChild("Brick")  --This looks in the Workspace for anything named "Brick", and sets the variable "found" to whatever object it finds.
  found.Name = "blah"  --Sets the object's name to "blah"
 
end
  if found ~= nil then  -- This makes sure that it actually found something. If the variable is nothing, then it ends.
 
    found.Name = "blah"  --Sets the object's name to "blah"
 
  end  --End the If loop
 
end --End the While loop
 
</pre>
</pre>


==Recursive==
==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.


Recursive sets whether the function should look inside of objects in the calling object, as well as the calling object.
For example, if there is a part in Workspace called "Part" and you use:
 
part = Game:FindFirstChild("Part", true)
For example, if there is a part in workspace called "Part" and you use:
<pre>
game:FindFirstChild("Part", true)
</pre>
It will find the part.
It will find the part.
part = Game:FindFirstChild("Part", false)
OR
part = Game:FindFirstChild("Part")
Will not.

Revision as of 02:52, 18 May 2010

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

Example

--This looks in the Workspace for anything named "Brick", 
-- and sets the variable "found" to whatever object it finds.
-- if nothing is found, then found is nil.
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

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 Workspace called "Part" and you use:

part = Game:FindFirstChild("Part", true)

It will find the part.

part = Game:FindFirstChild("Part", false)

OR

part = Game:FindFirstChild("Part")

Will not.