--[[
	FE Invisible Fling
	By: Diemiers#4209
	Modded By: OpenGamerTips	
	
	Keybinds:
	Z to Start
	X to Respawn

	Mods:
	- Made More Readable
	- Made Changeable Fly Speeds
	- Fixed Spam X Bug (Man, the creator was lazy.)
	- Cleaned Up Code
]]--

--------------------
-- Changeable Speeds:
speed = 20
maxspeed = 120
--------------------

lockedstate = false
	spawn(function()
		local message = Instance.new("Message", workspace)
		message.Text = "Modded Invisible Fling Loaded\nPress Z to start\nPress X to respawn"
		wait(2)
		message:Destroy()
	end)

	local mouse = game:GetService("Players").LocalPlayer:GetMouse()
	local groot = nil

	mouse.KeyDown:connect(function(k)
		if k == "z" then
			spawn(function()
				local message = Instance.new("Message", workspace)
				message.Text = "Please Wait...\nWe are bypassing your respawn timer"
				wait(11)
				message:Destroy()
			end)

			local ch = game:GetService("Players").LocalPlayer.Character
			local prt = Instance.new("Model", workspace)
			local z1 =  Instance.new("Part", prt)
			z1.Name = "Torso"
			z1.CanCollide = false
			z1.Anchored = true
			local z2  = Instance.new("Part", prt)
			z2.Name = "Head"
			z2.Anchored = true
			z2.CanCollide = false
			local z3 = Instance.new("Humanoid", prt)
			z3.Name = "Humanoid"
			z1.Position = Vector3.new(0, 9999, 0)
			z2.Position = Vector3.new(0, 9991, 0)
			game:GetService("Players").LocalPlayer.Character = prt
			wait(5)
			game:GetService("Players").LocalPlayer.Character = ch
			wait(6)

			local plr = game:GetService("Players").LocalPlayer
			mouse = plr:GetMouse()

			local Hum = Instance.new("Humanoid")
			Hum.Parent = game:GetService("Players").LocalPlayer.Character

			local root =  game:GetService("Players").LocalPlayer.Character.HumanoidRootPart

			for i, v in pairs(plr.Character:GetChildren()) do
		
				if v ~= root and  v.Name ~= "Humanoid" then
			
					v:Destroy()
			
				end
			end
			
			workspace.CurrentCamera.CameraSubject = root

			local se = Instance.new("SelectionBox", root)
			se.Adornee = root

			game:GetService('RunService').Stepped:connect(function()
				game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CanCollide = false
			end)
			game:GetService('RunService').RenderStepped:connect(function()
				game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CanCollide = false
			end)

			local power = 999999 

			power = power * 10

			wait(.1)
			local bambam = Instance.new("BodyThrust")
			bambam.Parent = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart
			bambam.Force = Vector3.new(power, 0, power)
			bambam.Location = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position 

			local plr = game:GetService("Players").LocalPlayer
			local torso = root
			local flying = true
			local deb = true
			local ctrl = {
				f = 0,
				b = 0,
				l = 0,
				r = 0
			}
			local lastctrl = {
				f = 0,
				b = 0,
				l = 0,
				r = 0
			}

			groot = root
	
			function Fly()
				local bg = Instance.new("BodyGyro", torso)
				bg.P = 9e4
				bg.maxTorque = Vector3.new(0, 0, 0)
				bg.cframe = torso.CFrame
				local bv = Instance.new("BodyVelocity", torso)
				bv.velocity = Vector3.new(0, 0, 0)
				bv.maxForce = Vector3.new(9e9, 9e9, 9e9)
				repeat
					wait()

					if ctrl.l + ctrl.r ~= 0 or ctrl.f + ctrl.b ~= 0 then
						speed = speed + .2
						if speed > maxspeed then
							speed = maxspeed
						end
					elseif not (ctrl.l + ctrl.r ~= 0 or ctrl.f + ctrl.b ~= 0) and speed ~= 0 then
						speed = speed - 1
						if speed < 0 then
							speed = 0
						end
					end
					if (ctrl.l + ctrl.r) ~= 0 or (ctrl.f + ctrl.b) ~= 0 then
						bv.velocity = ((workspace.CurrentCamera.CoordinateFrame.lookVector * (ctrl.f + ctrl.b)) + ((workspace.CurrentCamera.CoordinateFrame * CFrame.new(ctrl.l + ctrl.r, (ctrl.f + ctrl.b) * .2, 0).p) - workspace.CurrentCamera.CoordinateFrame.p)) * speed
						lastctrl = {
							f = ctrl.f,
							b = ctrl.b,
							l = ctrl.l,
							r = ctrl.r
						}
					elseif (ctrl.l + ctrl.r) == 0 and (ctrl.f + ctrl.b) == 0 and speed ~= 0 then
						bv.velocity = ((workspace.CurrentCamera.CoordinateFrame.lookVector * (lastctrl.f + lastctrl.b)) + ((workspace.CurrentCamera.CoordinateFrame * CFrame.new(lastctrl.l + lastctrl.r, (lastctrl.f + lastctrl.b) * .2, 0).p) - workspace.CurrentCamera.CoordinateFrame.p)) * speed
					else
						bv.velocity = Vector3.new(0, 0.1, 0)
					end

				until not flying
				ctrl = {
					f = 0,
					b = 0,
					l = 0,
					r = 0
				}
				lastctrl = {
					f = 0,
					b = 0,
					l = 0,
					r = 0
				}
				speed = 0
				bg:Destroy()
				bv:Destroy()

			end
			mouse.KeyDown:connect(function(key)
				if key:lower() == "e" then
					if flying then
						flying = false
					else
						flying = true
						Fly()
					end
				elseif key:lower() == "w" then
					ctrl.f = 1
				elseif key:lower() == "s" then
					ctrl.b = -1
				elseif key:lower() == "a" then
					ctrl.l = -1
				elseif key:lower() == "d" then
					ctrl.r = 1
				end
			end)
			mouse.KeyUp:connect(function(key)
				if key:lower() == "w" then
					ctrl.f = 0
				elseif key:lower() == "s" then
					ctrl.b = 0
				elseif key:lower() == "a" then
					ctrl.l = 0
				elseif key:lower() == "d" then
					ctrl.r = 0
				elseif key:lower() == "r" then

				end
			end)
			Fly()

		elseif k == "x" then
			if lockedstate == false then
				local lockedstate = true

				spawn(function()
					local message = Instance.new("Message", workspace)
					message.Text = "Respawning Character..."
					wait(1)
					message:Destroy()
				end)
				
				local saved = groot.Position
				local ch = game:GetService("Players").LocalPlayer.Character
				local prt = Instance.new("Model", workspace)
				local z1 =  Instance.new("Part", prt)
				z1.Name = "Torso"
				z1.CanCollide = false
				z1.Anchored = true
				local z2  = Instance.new("Part", prt)
				z2.Name = "Head"
				z2.Anchored = true
				z2.CanCollide = false
				local z3 = Instance.new("Humanoid", prt)
				z3.Name = "Humanoid"
				z1.Position = Vector3.new(0, 9999, 0)
				z2.Position = Vector3.new(0, 9991, 0)
				game:GetService("Players").LocalPlayer.Character = prt
				wait(5)
				game:GetService("Players").LocalPlayer.Character = ch
				local poop = nil
				repeat
					wait()
					poop = game:GetService("Players").LocalPlayer.Character:FindFirstChild("Head")
				until poop ~= nil
				wait(1)
				game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(saved)
				lockedstate = false
			end
		end
	end)