So I have this gas code that when you press w a s d it will lose gas, but it does not work when put in a seat, any help?
wait(1)
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 = 1000
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
if running then return end
running = true
while running and stamina > 0 do
fill:TweenSize(UDim2.new(stamina * 0.001, 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
game:GetService("UserInputService").InputBegan:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.D then
-- stuff here
end
end)
Also just nest another if statement if you wanted to check for the Running bool
wait(1)
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 = 1000
local canRun = true
running = false
game:GetService("UserInputService").InputBegan:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.D then
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
if running then return end
running = true
while running and stamina > 0 do
fill:TweenSize(UDim2.new(stamina * 0.001, 0, 1, 0), "Out", "Quad", 0.5)
stamina = stamina - 3
wait(0.5)
end
end
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