[SOLVED] Jetpack fuel randomly speeding up

  1. What do you want to achieve?
    I been making a jetpack that is supposed to drain fuel while flying and recharge while not flying, I managed to get it to work but the fuel is the issue.
  2. What is the issue?
    If you stand still and don’t press any buttons the fuel drains normally but if you press any button on your keyboard or mouse it starts to speed up the drain and the refill.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried almost everything but nothing seems to work, there is not a lot on the internet about jetpack issues like this so nothing much I can do.


local KeyCode = Enum.KeyCode.Z
local KeyCode2 = Enum.KeyCode.X
local HoverAnimID = "rbxassetid://11473519622"
local FlyAnimID = "rbxassetid://11474019583"
local WindSoundEnabled = false

local fuel = 1

local BodyVelocity = script:WaitForChild("BodyVelocity"):Clone()
local v3 = script.BodyGyro:Clone()
local Character = script.Parent
local Humanoid = Character:FindFirstChild("Humanoid") or Character:WaitForChild("Humanoid")
BodyVelocity.Parent = Character
v3.Parent = Character
local Hover = Instance.new("Animation")
Hover.AnimationId = HoverAnimID
local Fly = Instance.new("Animation")
Fly.AnimationId = FlyAnimID
local Sound1 = Instance.new("Sound", Character.HumanoidRootPart)
Sound1.SoundId = "rbxassetid://3308152153"
Sound1.Name = "Sound1"
if WindSoundEnabled == false then
	Sound1.Volume = 0
end

local Sound2 = Instance.new("Sound", Character.HumanoidRootPart)
Sound2.SoundId = "rbxassetid://11483048367"
Sound2.Name = "Sound2"
Sound2.Volume = 1.232
Sound2.Parent = Character.HumanoidRootPart

local Fire1 = Character:WaitForChild("Jetpack"):WaitForChild("Firepart2"):WaitForChild("Fire")
local Fire2 = Character:WaitForChild("Jetpack"):WaitForChild("Firepart"):WaitForChild("Fire")
local v10 = Humanoid.Animator:LoadAnimation(Hover)
local v11 = Humanoid.Animator:LoadAnimation(Fly)
local Camera = game.Workspace.Camera
local function u2()
	if Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
		return Humanoid.MoveDirection
	end
	local v12 = (Camera.CFrame * CFrame.new((CFrame.new(Camera.CFrame.p, Camera.CFrame.p + Vector3.new(Camera.CFrame.lookVector.x, 0, Camera.CFrame.lookVector.z)):VectorToObjectSpace(Humanoid.MoveDirection)))).p - Camera.CFrame.p;
	if v12 == Vector3.new() then
		return v12
	end
	return v12.unit
end
local Flymoving = script.Flymoving
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Flying = false

game:GetService("RunService").RenderStepped:Connect(function()
	if script.Parent == Character then
		if Flying == true then
			Humanoid:ChangeState(6)
			v3.CFrame = game.Workspace.Camera.CFrame
			if u2() == Vector3.new(0, 0, 0) then
				Flymoving.Value = false
			else
				Flymoving.Value = true
			end
			TweenService:Create(BodyVelocity, TweenInfo.new(0.3), {Velocity = u2() * 30}):Play()
		end
		
	end
end)

Flymoving.Changed:Connect(function(p1)
	if p1 == true then
		TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 85}):Play()
		v10:Stop()
		Sound1:Play()
		v11:Play()
		return
	end
	if p1 == false then
		TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 70}):Play()
		v11:Stop()
		Sound1:Stop()
		v10:Play()
	end
end)

local xractivated = false

UIS.InputBegan:Connect(function(key, gameProcessed)
	if gameProcessed then return end
	if key.KeyCode == KeyCode then
		if fuel >= 0.2 then
			if Flying == false then
				Flying = true
			Fire1.Enabled = true
			Fire2.Enabled = true
			Sound2:Play()
			if Character:FindFirstChild("HumanoidRootPart") then
				v10:Play(0.1, 1, 1)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
				Character.HumanoidRootPart.Running.Volume = 0
				Humanoid:ChangeState(6)
				BodyVelocity.Parent = Character.HumanoidRootPart
				v3.Parent = Character.HumanoidRootPart
				end
				end
		end
		
UIS.InputBegan:Connect(function(key, gameProcessed)
			if gameProcessed then return end
			if key.KeyCode == KeyCode2 then
				Flying = false
				Fire1.Enabled = false
				Fire2.Enabled = false
				Flymoving.Value = false
				Sound2:Stop()
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, true)
				Character.HumanoidRootPart.Running.Volume = 0.65
				Humanoid:ChangeState(8)
				BodyVelocity.Parent = Character
				v3.Parent = Character
				v10:Stop()
				v11:Stop()
			end
		end)
		end


	while Flying do
	
	wait()
	fuel = fuel - 0.001
	local size = game.Players.LocalPlayer.PlayerGui.FuelGui.BarBG.FuelBar
		size:TweenSize(UDim2.new(fuel, 0, 1, 0), "InOut", "Linear", 0.03)

		if fuel <= 0.001 then
			Sound2:Stop()
				Flying = false
				Fire1.Enabled = false
				Fire2.Enabled = false
				Flymoving.Value = false
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, true)
				Character.HumanoidRootPart.Running.Volume = 0.65
				Humanoid:ChangeState(8)
				BodyVelocity.Parent = Character
				v3.Parent = Character
				v10:Stop()
				v11:Stop()
		end
		
		while not Flying and fuel < 1 do
			
	wait()
	fuel = fuel + 0.001
	local size = game.Players.LocalPlayer.PlayerGui.FuelGui.BarBG.FuelBar
	size:TweenSize(UDim2.new(fuel, 0, 1, 0), "InOut", "Linear", 0.03)
		end
		
		if fuel > 1 then
			fuel = 1
		end

	end
end)


I just need help to fix this small issue and it should all be good.

Ignore the music, I left my spotify on.

Turn it to feature, this is the fix.

1 Like

Wish I could do that but sadly I am paid.

Hi! This is probably caused by you having 2 InputBegan events. My guess is that both of them are draining it at the same time causing your issue.

Please use if statements instead of making more than one event.

The first input is to start flying and the second one is to stop flying.

use print statements to see which of the (segments that do jetpack fuel thing) is playing.

I used print statements before this but I still had the same issues and no info that could help me.