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

Why won't this enable the Particle Emitter?

Asked by 9 years ago

So, I want to make it so when the player's health is below 25 it will enable a particle emitter.
This is in the Humanoid of a character called Model. The emitter is in the Torso.

local Humanoid = script.Parent

if Humanoid.Health < 25 then
        script.Parent.Parent.Torso.ParticleEmmiter.Enabled = true
        else
        script.Parent.Parent.Torso.ParticleEmmiter.Enabled = false
end

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

Your problem is that it's only checking the health once, right when the first player loads into the game. To fix this, you could connect it to any one of a few possible events, or just use a loop. So, let's go ahead and use the HealthChanged event.


local Humanoid = script.Parent

Humanoid.HealthChanged:connect(function(NewHealth) --Fires every time the health changes
    if NewHealth < 25 then --Checks the new health of the humanoid.
        script.Parent.Parent.Torso.ParticleEmmiter.Enabled = true
    else
        script.Parent.Parent.Torso.ParticleEmmiter.Enabled = false
    end
end)

All this does, is fires a function every time the Humanoids health changes. So it should, in theory track every health change that's made to the Humanoid.


So now your code should work properly. If you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P

Ad

Answer this question