FindFirstChild (Function): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mr Doom Bringer
No edit summary
>Travisdep
Line 13: Line 13:
function OnTouched(hit)
function OnTouched(hit)
  brick = hit.Parent:FindFirstChild("Torso")
  brick = hit.Parent:FindFirstChild("Torso")
if (brick ~= nil) then
  brick.BrickColor = BrickColor.new(1)
end
end
script.Parent.Touched:connect(OnTouched)
</pre>
==It can also be used to find objects with spaces==
<pre>
function OnTouched(hit)
brick = hit.Parent:FindFirstChild("Left Leg")
  if (brick ~= nil) then
  if (brick ~= nil) then
   brick.BrickColor = BrickColor.new(1)
   brick.BrickColor = BrickColor.new(1)

Revision as of 01:20, 29 January 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


function OnTouched(hit)
 brick = hit.Parent:FindFirstChild("Torso")
 if (brick ~= nil) then
  brick.BrickColor = BrickColor.new(1)
 end
end

script.Parent.Touched:connect(OnTouched)

It can also be used to find objects with spaces


function OnTouched(hit)
 brick = hit.Parent:FindFirstChild("Left Leg")
 if (brick ~= nil) then
  brick.BrickColor = BrickColor.new(1)
 end
end

script.Parent.Touched:connect(OnTouched)