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

Why isn't my my exploding barrel script not working... ? (I hate that title requirement...)

Asked by 6 years ago

I'm making a barrel that can explode, but it doesn't want to work no matter what I do. To make things more clear I'm using a normal script, Humanoid, Torso, Head

This is the script, nothing functions... :

Heater = script.Parent.Torso
Neon = script.Parent.Head
Humanoid = script.Parent.Humanoid
Fire = Heater.Fire
Smoke = Heater.Smoke

if Humanoid.Health <= 75 then
    Neon.BrickColor = BrickColor.new("Bright yellow")
end

if Humanoid.Health <= 50 then
    Neon.BrickColor = BrickColor.new("Orange")
    Fire.Enabled = true
end

if Humanoid.Health <= 25 then
    Neon.BrickColor = BrickColor.new("Crimson")
end

if Humanoid.Health == 0 then
    Exp = Instance.new("Explosion")
    Exp.BlastPressure = 100000
    Exp.BlastRadius = 7.5
    Exp.Parent = game.Workspace
    Exp.Position = Heater.Position
    Heater:Destroy()
    Neon:Destroy()
end

Hope you can find the error and help me fix it, please !

0
What's with the (I hate that title requirement...) ? Well, I wanted to give it the same title as it is right now, but it didn't work so i just wrote it there... LordTechet 53 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

Your script only runs once when the game first starts. To make it update every time the player’s health is changed, you must check the health every time the property changes.

Heater = script.Parent.Torso
Neon = script.Parent.Head
Humanoid = script.Parent.Humanoid
Fire = Heater.Fire
Smoke = Heater.Smoke

Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    if Humanoid.Health <= 75 and Humanoid.Health > 50 then
        Neon.BrickColor = BrickColor.new("Bright yellow")
    elseif Humanoid.Health <= 50 and Humanoid.Health > 25 then
        Neon.BrickColor = BrickColor.new("Orange")
        Fire.Enabled = true
    elseif Humanoid.Health <= 25 and Humanoid.Health > 0 then
        Neon.BrickColor = BrickColor.new("Crimson")
    elseif Humanoid.Health <= 0 then
        Exp = Instance.new("Explosion")
        Exp.BlastPressure = 100000
        Exp.BlastRadius = 7.5
        Exp.Parent = game.Workspace
        Exp.Position = Heater.Position
        Heater:Destroy()
        Neon:Destroy()
    end
end)
0
Sorry, still does not function, this will not be considered as "Answered" LordTechet 53 — 6y
Ad

Answer this question