local G=0 local z=nil local q=196.66666666667 local u=5 local t=false local P=1000 while Tool==nil do Tool=script.Parent wait(.5)end local c=Tool:FindFirstChild("\067\117\114\114\070\117\101\108")while c==nil do Tool=script.Parent c=Tool:FindFirstChild("\067\117\114\114\070\117\101\108")wait(.5)end local S=Tool.CurrFuel.Value local l=nil local H=nil local Z=nil local V=false local M=Instance.new("\066\111\100\121\086\101\108\111\099\105\116\121")M.velocity=Vector3.new(0,0,0)local A=Instance.new("\066\111\100\121\071\121\114\111")A.P=20000 A.D=8000 A.maxTorque=Vector3.new(A.P,A.P,A.P)local X=nil local U=nil function onEquippedLocal(q)z=Tool.Parent while z.Name=="\066\097\099\107\112\097\099\107"do z=Tool.Parent wait(.5)end equipPack()G=recursiveGetLift(z)M.P=G*10 M.maxForce=Vector3.new(0,M.P,0)q.Button1Down:connect(thrust)q.Button1Up:connect(cutEngine)X=game.Workspace.CurrentCamera H=z.Humanoid:LoadAnimation(Tool.standstill)H:Play()l=Tool.FuelGui:clone()updateGUI()l.Parent=(game.Players:GetPlayerFromCharacter(z)).PlayerGui V=true regenFuel()end function equipPack()Z=Tool.Handle:clone()Z.CanCollide=false Z.Name="\074\101\116\080\097\099\107"Z.Parent=game.Workspace Tool.Handle.Transparency=1 local G=Instance.new("\087\101\108\100")G.Part0=Z G.Part1=z.UpperTorso G.C0=CFrame.new(Vector3.new(0,0,-1))G.Parent=Z U=Instance.new("\080\097\114\116")U.Name="\070\108\097\109\101"U.Transparency=1 U.CanCollide=false U.Locked=true U.formFactor=2 U.Size=Vector3.new(1,.4,1)U.Parent=Z local q=Instance.new("\070\105\114\101")q.Heat=-12 q.Size=4 q.Enabled=false q.Parent=U local u=Instance.new("\087\101\108\100")u.Part0=Z.Flame u.Part1=Z u.C0=CFrame.new(Vector3.new(0,2,0))u.Parent=Z.Flame end function updateGUI()l.Frame.Size=UDim2.new(0,40,0,300*(Tool.CurrFuel.Value/P))l.Frame.Position=UDim2.new(.9,0,.2+.2*((P-Tool.CurrFuel.Value)/P),0)end function onUnequippedLocal()V=false if M~=nil then M:remove()end if A~=nil then A:remove()end if H~=nil then H:Stop()H:remove()end if l~=nil then l:remove()end if Z~=nil then Z:remove()Z=nil end Tool.Handle.Transparency=0 end Tool.Equipped:connect(onEquippedLocal)Tool.Unequipped:connect(onUnequippedLocal)function thrust()if S>0 then thrusting=true M.Parent=z.UpperTorso Z.Flame.Fire.Enabled=true Tool.Handle.InitialThrust:Play()A.Parent=z.UpperTorso while thrusting do A.cframe=X.CoordinateFrame M.velocity=Vector3.new(0,X.CoordinateFrame.lookVector.unit.y,0)*50 S=S-1 Tool.CurrFuel.Value=S if S<=0 then Tool.Handle.EngineFail:Play()cutEngine()end updateGUI()wait()Tool.Handle.Thrusting:Play()if S<=200 then Tool.Handle.LowFuelWarning:Play()end end Tool.Handle.Thrusting:Stop()Tool.Handle.LowFuelWarning:Stop()end end function cutEngine()thrusting=false Z.Flame.Fire.Enabled=false M.velocity=Vector3.new(0,0,0)M.Parent=nil H:Stop()A.Parent=nil end local s=nil function recursiveGetLift(G)local z=0 local t=G:GetChildren()if G:FindFirstChild("\072\101\097\100")~=nil then s=G:FindFirstChild("\072\101\097\100")end for G=1,#t,1 do if t[G].className=="\080\097\114\116"then if s~=nil and(t[G].Position-s.Position).magnitude<10 then if t[G].Name=="\072\097\110\100\108\101"then z=z+(t[G]:GetMass()*q)*1 else z=z+(t[G]:GetMass()*q)*u end end end z=z+recursiveGetLift(t[G])end return z end function regenFuel()while V do if S<P then S=S+1 Tool.CurrFuel.Value=S updateGUI()end wait(.2)end end
--while Tool == nil do
--	Tool = script.Parent
--	wait(.5)
--end

local mass = 0
local player = nil
local equalizingForce = 236 / 1.2 -- amount of force required to levitate a mass
local gravity = 5 -- things float at > 1
local moving = false

local maxFuel = 1000

while Tool == nil do
	Tool = script.Parent
	wait(0.5)
end

local currfuel = Tool:FindFirstChild("CurrFuel")
while currfuel == nil do
	Tool = script.Parent
	currfuel = Tool:FindFirstChild("CurrFuel")
	wait(0.5)
end

local fuel = Tool.CurrFuel.Value

local gui = nil

local anim = nil

local jetPack = nil

local regen = false

local force = Instance.new("BodyVelocity")
force.velocity = Vector3.new(0, 0, 0)

local bodyGyro = Instance.new("BodyGyro")
bodyGyro.P = 20000
bodyGyro.D = 8000
bodyGyro.maxTorque = Vector3.new(bodyGyro.P, bodyGyro.P, bodyGyro.P)

local cam = nil

local Flame = nil

function onEquippedLocal(mouse)
	player = Tool.Parent
	while player.Name == "Backpack" do
		player = Tool.Parent
		wait(0.5)
	end

	equipPack()
	mass = recursiveGetLift(player)
	force.P = mass * 10
	force.maxForce = Vector3.new(0, force.P, 0)
	mouse.Button1Down:connect(thrust)
	mouse.Button1Up:connect(cutEngine)
	cam = game.Workspace.CurrentCamera
	anim = player.Humanoid:LoadAnimation(Tool.standstill)
	anim:Play()
	gui = Tool.FuelGui:clone()
	updateGUI()
	gui.Parent = game.Players:GetPlayerFromCharacter(player).PlayerGui

	regen = true
	regenFuel()
end

function equipPack()
	jetPack = Tool.Handle:clone()
	jetPack.CanCollide = false
	jetPack.Name = "JetPack"

	jetPack.Parent = game.Workspace

	Tool.Handle.Transparency = 1

	local welder = Instance.new("Weld")
	welder.Part0 = jetPack
	welder.Part1 = player.UpperTorso
	welder.C0 = CFrame.new(Vector3.new(0, 0, -1))
	welder.Parent = jetPack

	Flame = Instance.new("Part")
	Flame.Name = "Flame"
	Flame.Transparency = 1
	Flame.CanCollide = false
	Flame.Locked = true
	Flame.formFactor = 2
	Flame.Size = Vector3.new(1, 0.4, 1)
	Flame.Parent = jetPack

	local Fire = Instance.new("Fire")
	Fire.Heat = -12
	Fire.Size = 4
	Fire.Enabled = false
	Fire.Parent = Flame

	local firer = Instance.new("Weld")
	firer.Part0 = jetPack.Flame
	firer.Part1 = jetPack
	firer.C0 = CFrame.new(Vector3.new(0, 2, 0))
	firer.Parent = jetPack.Flame
end

function updateGUI()
	gui.Frame.Size = UDim2.new(0, 40, 0, 300 * (Tool.CurrFuel.Value / maxFuel))
	gui.Frame.Position = UDim2.new(0.9, 0, 0.2 + (0.2 * ((maxFuel - Tool.CurrFuel.Value) / maxFuel)), 0)
end

function onUnequippedLocal()
	regen = false
	if force ~= nil then
		force:remove()
	end
	if bodyGyro ~= nil then
		bodyGyro:remove()
	end
	if anim ~= nil then
		anim:Stop()
		anim:remove()
	end
	if gui ~= nil then
		gui:remove()
	end
	if jetPack ~= nil then
		jetPack:remove()
		jetPack = nil
	end
	Tool.Handle.Transparency = 0
end

Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)

function thrust()
	if fuel > 0 then
		thrusting = true
		force.Parent = player.UpperTorso
		jetPack.Flame.Fire.Enabled = true
		Tool.Handle.InitialThrust:Play()
		bodyGyro.Parent = player.UpperTorso
		while thrusting do
			bodyGyro.cframe = cam.CoordinateFrame
			force.velocity = Vector3.new(0, cam.CoordinateFrame.lookVector.unit.y, 0) * 50

			fuel = fuel - 1
			Tool.CurrFuel.Value = fuel
			if fuel <= 0 then
				Tool.Handle.EngineFail:Play()
				cutEngine()
			end
			updateGUI()
			wait()

			Tool.Handle.Thrusting:Play()

			if fuel <= 200 then
				Tool.Handle.LowFuelWarning:Play()
			end
		end
		Tool.Handle.Thrusting:Stop()
		Tool.Handle.LowFuelWarning:Stop()
	end
end

function cutEngine()
	thrusting = false
	jetPack.Flame.Fire.Enabled = false
	force.velocity = Vector3.new(0, 0, 0)
	force.Parent = nil
	anim:Stop()
	bodyGyro.Parent = nil
end

local head = nil
function recursiveGetLift(node)
	local m = 0
	local c = node:GetChildren()
	if node:FindFirstChild("Head") ~= nil then
		head = node:FindFirstChild("Head")
	end -- nasty hack to detect when your parts get blown off

	for i = 1, #c do
		if c[i].className == "Part" then
			if head ~= nil and (c[i].Position - head.Position).magnitude < 10 then -- GROSS
				if c[i].Name == "Handle" then
					m = m + (c[i]:GetMass() * equalizingForce * 1) -- hack that makes hats weightless, so different hats don't change your jump height
				else
					m = m + (c[i]:GetMass() * equalizingForce * gravity)
				end
			end
		end
		m = m + recursiveGetLift(c[i])
	end
	return m
end

function regenFuel()
	while regen do
		if fuel < maxFuel then
			fuel = fuel + 1
			Tool.CurrFuel.Value = fuel
			updateGUI()
		end
		wait(0.2)
	end
end
