FindFirstChild (Function): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>GoldenUrg
Added link
>GoldenUrg
Added link
(No difference)

Revision as of 04:10, 14 June 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.

See Also

Instance Hierarchy