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
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.