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") | |||
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== | ||
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) | |||
For example, if there is a part in | |||
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
|
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.