FindFirstChild (Function): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Gordonrox24
Undo revision 29826 by Gordonrox24 (Talk) weird stuff
>Mr Doom Bringer
No edit summary
Line 1: Line 1:
{{Function|
<onlyinclude>{{Function|
name                  = FindFirstChild
name                  = FindFirstChild
|arguments            = [[String]] Name, [[Bool]] recursive
|arguments            = [[String]] Name, [[Bool]] recursive
Line 5: Line 5:
|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>





Revision as of 21:02, 22 April 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


while true do  --Starts up a While loop
  found = game.Workspace:FindFirstChild("Brick")  --This looks in the Workspace for anything named "Brick", and sets the variable "found" to whatever object it finds.

  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

Recursive

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:

game:FindFirstChild("Part", true)

It will find the part.