So im trying to make a car that needs gas, but theres some thing that are hard to do, any help? Heres my code, the problems are it keeps making the value go down even when your not holding any buttons, 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 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