# Calculation of fuel consumption

Hi!
So…
I want to make realistic fuel consumption. This should be so that the higher the vehicle speed, the higher the fuel consumption. At the same time, low fuel consumption should exist even when the vehicle is not moving but the engine is running. And at the same time, I want fuel consumption to be adjustable for different vehicles.
The problem is that I’m not strong in math and I can’t figure out how to solve it.

I’ve been looking for solutions, but my problem seems to be rare
Here is the code I currently have.

``````local speed = math.ceil((math.floor((script.Parent.Parent.MAIN.Velocity).magnitude))/3) * 2
while wait(FuelUsage.Value) do
if Values.EngineOn.Value == true and FuelLevel.Value > 0 and script.Parent.LimitedFuel.Value == true then
FuelLevel.Value = FuelLevel.Value - 1
end
end

``````

This can seem very confusing. Ask if you don’t understand something.
Thanks!

1 Like

Whenever your speed variable changes, change the gas removing speed rate and if your car speed is 0 then set the gas removing to whatever you’d like

1 Like

Thanks! A simple and logical solution. But it got my brain working again.

1 Like

then depending on the vehicle you may multiply the value of the gas removing speed to whatever you’d like, for example a car that spends a lot of gas would be gasRemoving * 2

1 Like