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

When I touched, it takes away all health?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

When I touched the oart that is located in script.Parent, it takes away all health. I want it to take away half.

Text = "You have gotten health taken away."

function Touched(hit) --"Touched" is name of the function.

    local hum = hit.Parent:findFirstChild("Humanoid")

    if hum then
        hum.Health = hum.Health - (hum.Health/2) --subtracts half the health, this won't ever kill the player though

        print(Text)
    end
end

script.Parent.Touched:connect(Touched)



1 answer

Log in to vote
1
Answered by
Bulvyte 388 Moderation Voter
8 years ago

Why don't you do this:

Text = "You have gotten health taken away."
ting = 0
function Touched(hit)

    local hum = hit.Parent:findFirstChild("Humanoid")

    if hum then
    if ting == 0 then
    ting = 1
        hum.Health = hum.Health -50 --subtracts 50 health from him
        print(Text)
        wait(1)
        ting = 0
        end
    end
end

script.Parent.Touched:connect(Touched)
Ad

Answer this question