Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This doesn't subtract health?

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

✓ Accepted answer

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 comment

1

Worked fantastically! You are truly amazing

This discussion is preserved as it was. New answers, comments, and votes are closed.