I'm making a fuel system and I want the car to stop when the fuel runs out. But .Changed:Connect() doesn't work! How can I fix this?
My Code:
if script.Parent.Parent.Name == "Plugins" then return end
local player = script.Parent.Parent.Parent.Parent
local playerName = player.Name
local car = game.Workspace["Car"..playerName]
local MaxAmount = car.Fuel.MaxFuel.Value
local DecreaseFrequency = car.Fuel.DecreaseFrequency.Value
local DecreaseAmount = car.Fuel.DecreaseAmount.Value
local fuel = car.Fuel
local Formula = math.clamp(fuel.Value/MaxAmount, 0, 1)
script.Parent.Bar:TweenSize(UDim2.new(Formula, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.15, true)
while true do
wait(DecreaseFrequency)
if fuel.Value >= 1 then
fuel.Value -= DecreaseAmount
end
end
fuel.Changed:Connect(function(NewValue)
print(NewValue)
print("FUEL!!!")
local Formula = math.clamp(fuel.Value/MaxAmount, 0, 1)
script.Parent.Bar:TweenSize(UDim2.new(Formula, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.15, true)
if fuel.Value <= 0 then
fuel.Value = 0
script.Parent.Bar.Visible = false
player.PlayerGui["A-Chassis Interface"].IsOn.Value = false
else
script.Parent.Bar.Visible = true
player.PlayerGui["A-Chassis Interface"].IsOn.Value = true
end
end)
