How would I make a car gas thing?

So i have a car that works fine, but I want to make it run on gas but dont know how to approach this, any help? So I would like to have a little gui at the bottem (Which is easy) but I dont know how I would go about making the car check for “gas” or how to make the gui go down depending on the gas value

Maybe add more details? Your post is fairly short and some more information would most definitely be helpful.

1 Like

I updated it so maybe this would help?

maybe have something to check if the car is moving, and if its moving then subtractgas() would subtract gas per 2 seconds car is moving or something like that?

Okay so this is what I have, It wont stop when the player presses w, it does not stop, any help??

local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local hum = player.Character:WaitForChild("Humanoid")
local fill = script.Parent
local stamina = 100
local canRun = true
running = false

UserInputService.InputBegan:connect(function(key, gameProcessedEvent)
	if not gameProcessedEvent and key.KeyCode == Enum.KeyCode.W and canRun then
		running = true
		while running and stamina > 0 do
			fill:TweenSize(UDim2.new(stamina * 0.01, 0, 1, 0), "Out", "Quad", 0.5)
			stamina = stamina - 3
			wait(0.5)
		end
	end
end)


UserInputService.InputEnded:connect(function(key, gameProcessedEvent)
	if not gameProcessedEvent and key.KeyCode == Enum.KeyCode.W then
		running = false		
	end
end)

while true do
	if not running and stamina < 100 then
		fill:TweenSize(UDim2.new(stamina * 0.01, 0, 1, 0), "Out", "Quad", 0.5)
	end
	if stamina >= 33 then
		canSprint = true
	elseif stamina == 0 then
		canSprint = false	
	end
	wait(0.5)
end

How would I make this so it does this for all WASD

any thing?

local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local hum = player.Character:WaitForChild("Humanoid")
local fill = script.Parent
local stamina = 100
local canRun = true
running = false

UserInputService.InputBegan:connect(function(key, gameProcessedEvent)
	if not gameProcessedEvent and canRun and key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.A or key.KeyCode == Enum.KeyCode.S or key.KeyCode == Enum.KeyCode.D then
		running = true
		while running and stamina > 0 do
			fill:TweenSize(UDim2.new(stamina * 0.01, 0, 1, 0), "Out", "Quad", 0.5)
			stamina = stamina - 3
			wait(0.5)
		end
	end
end)


UserInputService.InputEnded:connect(function(key, gameProcessedEvent)
	if not gameProcessedEvent and key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.A or key.KeyCode == Enum.KeyCode.S or key.KeyCode == Enum.KeyCode.D then
		running = false		
	end
end)

while true do
	if not running and stamina < 100 then
		fill:TweenSize(UDim2.new(stamina * 0.01, 0, 1, 0), "Out", "Quad", 0.5)
	end
	if stamina >= 33 then
		canSprint = true
	elseif stamina == 0 then
		canSprint = false	
	end
	wait(0.5)
end

Just make the GUI update every time the gas values changes, which I would hold in the car, and if they’re driving it would lose gas gradually.

If you wanted to make it more in depth you could have an index of all of the vehicles in the game and how fast they lose gas, might make it more interesting.

But yeah, that’s how i’d go about it.

But any help with my issue above? It keeps losing gas even after I stop pressing the buttons, am I doing something wrong?

I’d literally just make it so if they have the car on (realistic) it’s losing gas, you might have to make it so there’s a way you can check if the engine is on or not.

Also, if you just want to make it lose gas when they’re moving the car, use this:

Basically, use UIS to figure out if they’re holding down a button or not and if they are gradually lower the gas.

if the vehicle speed >0 then enter the script

Where would I put this? use my script please.