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

Why doesn't this script stop the damage when the enemy is dead?

Trying to figure out why this script won't stop the damage when enemy is dead. The enemy continues to deal damage through his limps on the ground after he is dead (I believe it is just the torso).

local canhit = true
local enemytorso = script.Parent:FindFirstChild('Torso')
if enemytorso and script.Parent.Enemy.Health > 0 then
	enemytorso.Touched:connect(function(hit)
		if hit.Parent:FindFirstChild('Humanoid') then
			if canhit then
				canhit = false
				hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
				wait(1)
				canhit = true
			end
		end
	end)
end

1 answer

✓ Accepted answer

Line 3 in your code is pretty much useless, it activates only once (when "Enemy" spawns). You should place that line 3 code after the .Touched event, so that it will check Enemy's health everytime it's touched.

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