Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesnt this work?

Asked by 8 years ago


function onTouched(hit) -- function local torso = hit:FindFirstChild('Torso') local rightleg = hit:FindFirstChild('RightLeg') local rightArm = hit:FindFirstChild('RightArm') local leftLeg = hit:FindFirstChild('LeftLeg') local leftArm = hit:FindFirstChild('LeftArm') local headfoil = hit:FindFirstChild('Head') torso.Transparency = 1 rightArm.Transparency = 1 rightleg.Transparency = 1 leftArm.Transparency = 1 leftLeg.Transparency = 1 headfoil.Transparency = 1 hit.Transparency = 1 end script.Parent.Touched:connect (onTouched) --listener

1 answer

Log in to vote
1
Answered by
Klamman 220 Moderation Voter
8 years ago

The touched event returns the part that touched the object in question. So if your leg touches a part, for example, your leg will be what the listener returns. If that's the case, when you touch a part and your function is run, your code is looking for the first child of the limb, not the player. To fix this you would change the code to

local torso = hit.Parent:FindFirstChild('Torso')
local rightleg = hit.Parent:FindFirstChild('RightLeg')
local rightArm = hit.Parent:FindFirstChild('RightArm')
local leftLeg = hit.Parent:FindFirstChild('LeftLeg')
local leftArm = hit.Parent:FindFirstChild('LeftArm')
local headfoil = hit.Parent:FindFirstChild('Head')

Also, the space between "connect" and the function in your listener seems unnecessary, but that could just be styling. Hope this helps!

Ad

Answer this question