Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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."

5 comments

0

Because the script only works once, put it in a HealthChanged event

0

Can you edit the script? I've never used a HealthChanged event before. I mainly don't know where it goes.

0

do you think maybe the acceleration of the smoke it too small ?

0

Excuse me what

0

I would see the smoke just fine when it gets enabled before I press Play.

1 answer

✓ Accepted answer

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.

9 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.

0

I might be doing something wrong in my setup... Because this script seems too legit to be wrong...

0

I'm assuming OP wants the health to at least be 1000.

0

It's a Humvee.

0

The vehicle is actually suppose to be 2000 MaxHealth. And I'm using a 28 Health-taking gun.

0

Wait, is that suppose to be a LocalScript or Script?

0

Server if the smoke should be replicated

0

It still doesn't work.

0

Thanks for the help! Now i have to figure out the gun script

This discussion is preserved as it was. New answers, comments, and votes are closed.