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

Better way to get a touched event?

Asked by 8 years ago

I have been trying to create events that happen when you touch a part with a certain name such as "Kill" on touch of the brick but i have been noticing that the .touched event is not very reliable for getting when a users leg has touched the part. Is there a better way to do this?

function KillOnLeg(touched)
    if touched:IsA("Part") then
            if touched.Name == "IntKill" or touched.Name == "Water" then
                P.Character.Humanoid.Health = -1
                wait()
            end
            if touched.Name == "Hurt10" then
                P.Character.Humanoid.Health = P.Character.Humanoid.Health - 10
                wait(2)
            end
            if touched.Name == "Hurt25" then
                P.Character.Humanoid.Health = P.Character.Humanoid.Health - 25
                wait(3)
            end
            if touched.Name == "Hurt50" then
                P.Character.Humanoid.Health = P.Character.Humanoid.Health - 50
            end
            if touched.Name == "Hurt75" then
                P.Character.Humanoid.Health = P.Character.Humanoid.Health - 75
                wait(4)
            end
        wait(2)
    end
end


P.Character["Right Leg"].Touched:connect(function(touched)
     if not activated then
        activated = true
        KillOnLeg(touched)
            wait(1.5)
    activated = false

    end
end)
P.Character["Left Leg"].Touched:connect(function(touched)
    if not activated then
        activated = true
            KillOnLeg(touched)
            wait(1.5)
        activated = false

    end


end)

Answer this question