Script Help Vehicle Health and FX

I’m working on making a custom vehicle health system and I’m trying to set it so when the vehicle’s health gets below 30, in enables the smoke so the vehicle starts smoking. I cannot get it to work and nothing is coming up in the output.

local health = script.Parent.Humanoid.Health

local speeder = script.Parent

if speeder.Health < 30 then
script.Parent.Parent.Seat.Smoke.Enabled = true
end

This is what my setup currently looks like.

Screenshot_39

3 Likes

You’d want a listener to detect when the health changes. You can use a Humanoid.HealthChanged event to listen for when the humanoids health changes.

local health = script.Parent.Humanoid.Health
local speeder = script.Parent

speeder.Humanoid.HealthChanged:Connect(function()
    if health < 30 then
       script.Parent.Parent.Seat.Smoke.Enabled = true
    end
end)
2 Likes

Thank you. I’m finally putting aside building to learn some more scripting and this website has helped a ton. Would that be in a local script or normal script?

2 Likes

That would be in a regular script (server-sided).

Still won’t start smoking. No output errors though.

I believe you should check the health of the car every time it changes. Currently, the value of the health is being set to a variable at the start: local health = script.Parent.Humanoid.Health. Instead, you should run this:

local human = script.Parent.Humanoid
local speeder = script.Parent
speeder.Humanoid.HealthChanged:Connect(function()
    if human.health < 30 then
       script.Parent.Parent.Seat.Smoke.Enabled = true
    end
end)
2 Likes