FindFirstChild (Function): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mr Doom Bringer
m Reverted edit of Travisdep, changed back to last version by Mr Doom Bringer
>Mr Doom Bringer
No edit summary
Line 11: Line 11:
<pre>
<pre>


function OnTouched(hit)
while true do  --Starts up a While loop
brick = hit.Parent:FindFirstChild("Torso")
  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 (brick ~= nil) then
  brick.BrickColor = BrickColor.new(1)
end
end


script.Parent.Touched:connect(OnTouched)
  if brick ~= nil then  -- This makes sure that it actually found something. If the variable is nothing, then it ends.
 
    brick.Name = "blah"  --Sets the object's name to "blah"
 
  end  --End the If loop
 
end  --End the While loop


</pre>
</pre>

Revision as of 00:04, 11 March 2008

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 brick ~= nil then  -- This makes sure that it actually found something. If the variable is nothing, then it ends.

    brick.Name = "blah"  --Sets the object's name to "blah"

  end  --End the If loop

end  --End the While loop