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

Why is my script not working correctly?

Asked by
IcyEvil 260 Moderation Voter
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

my script is trying to make it to where every second, you lose 5 Health, but It just automatically kills you, the second you touch the part(this is a script within a part)

local HealthLoss = 5

script.Parent.Touched:connect(function(hit)
    if hit.Parent then
        local hum = hit.Parent:findFirstChild("Humanoid")
         if hum then
            droppedhealth = HealthLoss - HealthLoss
            hum.Health = droppedhealth
        end
        end
end)

Any and all help is welcomed, maybe a reason on why this code persay was not working?

1 answer

Log in to vote
2
Answered by 8 years ago

Let's break it down

The variable droppedhealth is equal to HealthLoss minus itself, which is 0, then you are setting the Humanoid's health to droppedheatlh, which is 0.


How to fix

You could get the Humanoid's health, then subtract HealthLoss

local healthDrop = 5
part.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local hum = hit.Parent.Humanoid
        hum.Health = hum.Health - healthDrop
    end
end)
0
Thank you, this is very helpful! IcyEvil 260 — 8y
Ad

Answer this question