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

why is my Humanoid.HealthChanged not running?

Asked by 3 years ago
01for i, v in pairs(CurrentEnemies) do
02    v.Humanoid.HealthChanged:Connect(function()
03        if v.Humanoid.Health <= 0 then
04            print("healthlow")
05            --Add Coin Event
06            table.remove(CurrentEnemies, v)
07            Remaining.Value = Remaining.Value - 1
08            v:Destroy()
09 
10        end
11    end)
12end

runs through current enemies and checks if they died

but the .HealthChanged isnt firing.

1 answer

Log in to vote
1
Answered by 3 years ago

Try using the get property changed signal:

01for i, v in pairs(CurrentEnemies) do
02    v.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
03        if v.Humanoid.Health <= 0 then
04            print("healthlow")
05            --Add Coin Event
06            table.remove(CurrentEnemies, v)
07            Remaining.Value = Remaining.Value - 1
08            v:Destroy()
09 
10        end
11    end)
12end
Ad

Answer this question