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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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.

Ad

Answer this question