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

local currfuel = Tool:FindFirstChild("CurrFuel")
while currfuel == nil do
	Tool = script.Parent
	currfuel = Tool:FindFirstChild("CurrFuel")
	wait(.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(.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
