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

Can someone tell me how I could make Humanoid.Health enable a Smoke or Fire object?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a vehicle that is destructible with Humanoid. I can't seem to get it to work.

I want the smoke to enable when the health is at 1000.

But every time I make the health lower to 1000 from 2000, it does nothing. Here's the code I've made that didn't work:

local health = script.Parent.Humanoid
local damage1 = script.Parent.DamageInd.Smoke


if health.Health == 1000 then
    damage1.Enabled = true
    wait()
end

However, if I start the Test with 1000, it'll work, but it won't work if i manually change it through properties or shoot at it, it doesn't.

the DamageInd is the brick that has the fire/smoke. This script was placed within the model of the vehicle. The Humanoid was placed in it too.

I basically need to find a way to tell the script to "look again."

0
Because the script only works once, put it in a HealthChanged event Rare_tendo 3000 — 5y
0
Can you edit the script? I've never used a HealthChanged event before. I mainly don't know where it goes. Motakyatto 7 — 5y
0
do you think maybe the acceleration of the smoke it too small ? User#23252 26 — 5y
0
Excuse me what User#24403 69 — 5y
0
I would see the smoke just fine when it gets enabled before I press Play. Motakyatto 7 — 5y

1 answer

Log in to vote
3
Answered by 5 years ago

Your script only works once, and that is immediately when it starts running. It will not check again. Using the HealthChanged event, you can do your check. HealthChanged fires whenever the health changes, whether it be an increase or decrease, which should be when you're checking.

local humanoid = script.Parent.Humanoid
local damage1 = script.Parent.DamageInd.Smoke

humanoid.HealthChanged:Connect(function(health)
    -- health is the new health of the humanoid

    if health >= 1000 then 
        -- the health might be 1000.24146 and that isn't exactly 1000, so >=
        damage1.Enabled = true 
    end
end)

Hopefully this answered your question, and if it did, then don't forget to hit that accept button. If you have any other questions, then feel free to leave them down in the comments.
0
You might also want to flip that > sign as I would assume the smoke would be enabled for health <= 1000 thanks for reminding me about Connect. Vathriel 510 — 5y
0
I might be doing something wrong in my setup... Because this script seems too legit to be wrong... Motakyatto 7 — 5y
0
I'm assuming OP wants the health to at least be 1000. User#24403 69 — 5y
0
It's a Humvee. Motakyatto 7 — 5y
View all comments (5 more)
0
The vehicle is actually suppose to be 2000 MaxHealth. And I'm using a 28 Health-taking gun. Motakyatto 7 — 5y
0
Wait, is that suppose to be a LocalScript or Script? Motakyatto 7 — 5y
0
Server if the smoke should be replicated User#24403 69 — 5y
0
It still doesn't work. Motakyatto 7 — 5y
0
Thanks for the help! Now i have to figure out the gun script Motakyatto 7 — 5y
Ad

Answer this question