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

This doesn't subtract health?

Asked by
wackem 50
9 years ago

My code doesn't subtract the health. It's not the fact it's not the player's character it's hitting or something along the lines of that (I've already printed hit.Parent and it was the character). So I don't seem to see the problem

local b = script.Parent
local tool = b.Parent
local dmg = 10

b.Touched:connect(function(hit)
    local char = hit.Parent
    local hum = char:WaitForChild("Humanoid")
    if hum then
        local hth = hum.Health
        hth = hth - dmg
    end
end)

(Note it's an entirely new sword script mechanism for my game. I don't believe there is conflicting scripts. Unless hitting the bade is false if you are hitting during animation. I do not know.)

1 answer

Log in to vote
0
Answered by 9 years ago

Your problem is you referencing a value then trying to change the reference.

So instead of 'hth' being the actual health, it is just another value.

Instead do

hum.Health = hum.Health - dmg

But even better than that:

hum:TakeDamage(dmg)

Hope this helped

1
Worked fantastically! You are truly amazing wackem 50 — 9y
Ad

Answer this question