FindFirstChild (Function)

From Legacy Roblox Wiki
Revision as of 02:52, 18 May 2010 by >GoldenUrg (fixed layout; added examples)
Jump to navigationJump to search
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.