Tool=script.Parent Handle=Tool:WaitForChild("\072\097\110\100\108\101")Players=game:GetService("\080\108\097\121\101\114\115")RunService=game:GetService("\082\117\110\083\101\114\118\105\099\101")Camera=(game:GetService("\087\111\114\107\115\112\097\099\101")).CurrentCamera Animations={}LocalObjects={}ServerControl=Tool:WaitForChild("\083\101\114\118\101\114\067\111\110\116\114\111\108")ClientControl=Tool:WaitForChild("\067\108\105\101\110\116\067\111\110\116\114\111\108")Rate=.016666666666667 SpeedMultiplier=1.5 CameraSpeed={X=40*SpeedMultiplier;Z=60*SpeedMultiplier}Controls={Forward={Mode=false,Keys={Key="\119";ByteKey=17}};Backward={Mode=false;Keys={Key="\115";ByteKey=18}};Left={Mode=false;Keys={Key="\097",ByteKey=20}};Right={Mode=false,Keys={Key="\100";ByteKey=19}}}ToolEquipped=false function HandleFlightControl()if not CheckIfAlive()then return end if FightMonitor then FightMonitor:disconnect()end FightMonitor=Torso.ChildAdded:connect(function(o)if Flying then return end if o.Name=="\070\108\105\103\104\116\072\111\108\100"then local o=Torso:FindFirstChild("\070\108\105\103\104\116\083\112\105\110")local v=Torso:FindFirstChild("\070\108\105\103\104\116\080\111\119\101\114")local j=Torso:FindFirstChild("\070\108\105\103\104\116\072\111\108\100")if not o or not v or not j then return end Flying=true Humanoid.WalkSpeed=0 Humanoid.PlatformStand=true Humanoid.AutoRotate=false DisableJump(true)Torso.Velocity=Vector3.new(0,0,0)Torso.RotVelocity=Vector3.new(0,0,0)local S=false while Flying and(o.Parent and(v.Parent and(j.Parent and CheckIfAlive())))do local V=Vector3.new(0,0,0)local P=Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(0,0,-1))local g=Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(-1,0,0))local U=Camera.CoordinateFrame local L=(CFrame.new(Vector3.new(0,0,0),U.lookVector*Vector3.new(1,0,1))):vectorToObjectSpace(Humanoid.MoveDirection)V=V+((P*CameraSpeed.Z)*-L.z or V)V=V+((g*CameraSpeed.X)*-L.x or V)o.cframe=CFrame.new(Vector3.new(0,0,0),P)if V.magnitude<1 then j.maxForce=Vector3.new(j.P*100,j.P*100,j.P*100)v.maxForce=Vector3.new(0,0,0)if S then j.position=Torso.Position end S=false else S=true j.maxForce=Vector3.new(0,0,0)v.maxForce=Vector3.new(v.P*100,v.P*100,v.P*100)end v.velocity=V wait(Rate)end Flying=false if CheckIfAlive()then Torso.Velocity=Vector3.new(0,0,0)Torso.RotVelocity=Vector3.new(0,0,0)Humanoid.WalkSpeed=16 Humanoid.PlatformStand=false Humanoid.AutoRotate=true DisableJump(false)Humanoid:ChangeState(Enum.HumanoidStateType.Freefall)end end end)end function SetAnimation(o,v)if o=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(v and(ToolEquipped and Humanoid))then for o,j in pairs(Animations)do if j.Animation==v.Animation then j.AnimationTrack:Stop()table.remove(Animations,o)end end local o=Humanoid:LoadAnimation(v.Animation)table.insert(Animations,{Animation=v.Animation;AnimationTrack=o})o:Play(v.FadeTime,v.Weight,v.Speed)elseif o=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and v then for o,j in pairs(Animations)do if j.Animation==v.Animation then j.AnimationTrack:Stop()table.remove(Animations,o)end end end end function DisableJump(o)if PreventJump then PreventJump:disconnect()end if o then PreventJump=Humanoid.Changed:connect(function(o)if o=="\074\117\109\112"then Humanoid.Jump=false end end)end end function CheckIfAlive()return(Character and(Character.Parent and(Humanoid and(Humanoid.Parent and(Humanoid.Health>0 and(Torso and(Torso.Parent and(Player and Player.Parent))))))))and true or false end function KeyPress(o,v)local j=string.lower(o)local S=string.byte(j)for o,V in pairs(Controls)do if j==V.Keys.Key or S==V.Keys.ByteKey then Controls[o].Mode=v end end end function Equipped(o)Character=Tool.Parent Player=Players:GetPlayerFromCharacter(Character)Humanoid=Character:FindFirstChild("\072\117\109\097\110\111\105\100")Torso=Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")ToolEquipped=true if not CheckIfAlive()then return end o.KeyDown:connect(function(o)KeyPress(o,true)end)o.KeyUp:connect(function(o)KeyPress(o,false)end)Spawn(HandleFlightControl)end function Unequipped()Flying=false LocalObjects={}for o,v in pairs(Animations)do if v and v.AnimationTrack then v.AnimationTrack:Stop()end end for o,v in pairs({PreventJump;FightMonitor})do if v then v:disconnect()end end for o,v in pairs(Controls)do Controls[o].Mode=false end Animations={}ToolEquipped=false end function InvokeServer(o,v)local j pcall(function()j=ServerControl:InvokeServer(o,v)end)return j end function OnClientInvoke(o,v)if o=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(v and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",v)elseif o=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and v then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",v)elseif o=="\080\108\097\121\083\111\117\110\100"and v then v:Play()elseif o=="\083\116\111\112\083\111\117\110\100"and v then v:Stop()end end ClientControl.OnClientInvoke=OnClientInvoke Tool.Equipped:connect(Equipped)Tool.Unequipped:connect(Unequipped)
--Made by Luckymaxer

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Players = game:GetService("Players")
RunService = game:GetService("RunService")

Camera = game:GetService("Workspace").CurrentCamera

Animations = {}
LocalObjects = {}

ServerControl = Tool:WaitForChild("ServerControl")
ClientControl = Tool:WaitForChild("ClientControl")

Rate = (1 / 60)

SpeedMultiplier = 1.5

CameraSpeed = {
	X = 40 * SpeedMultiplier,
	Z = 60 * SpeedMultiplier,
}

Controls = {
	Forward = {
		Mode = false,
		Keys = { Key = "w", ByteKey = 17 },
	},
	Backward = {
		Mode = false,
		Keys = { Key = "s", ByteKey = 18 },
	},
	Left = {
		Mode = false,
		Keys = { Key = "a", ByteKey = 20 },
	},
	Right = {
		Mode = false,
		Keys = { Key = "d", ByteKey = 19 },
	},
}

ToolEquipped = false

function HandleFlightControl()
	if not CheckIfAlive() then
		return
	end
	if FightMonitor then
		FightMonitor:disconnect()
	end
	FightMonitor = Torso.ChildAdded:connect(function(Child)
		if Flying then
			return
		end
		if Child.Name == "FlightHold" then
			local FlightSpin = Torso:FindFirstChild("FlightSpin")
			local FlightPower = Torso:FindFirstChild("FlightPower")
			local FlightHold = Torso:FindFirstChild("FlightHold")
			if not FlightSpin or not FlightPower or not FlightHold then
				return
			end
			Flying = true
			Humanoid.WalkSpeed = 0
			Humanoid.PlatformStand = true
			Humanoid.AutoRotate = false
			DisableJump(true)
			Torso.Velocity = Vector3.new(0, 0, 0)
			Torso.RotVelocity = Vector3.new(0, 0, 0)
			local IsMoving = false
			while Flying and FlightSpin.Parent and FlightPower.Parent and FlightHold.Parent and CheckIfAlive() do
				local NewPush = Vector3.new(0, 0, 0)
				local ForwardVector = Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(0, 0, -1))
				local SideVector = Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(-1, 0, 0))

				local CoordinateFrame = Camera.CoordinateFrame
				local localControlVector =
					CFrame.new(Vector3.new(0, 0, 0), CoordinateFrame.lookVector * Vector3.new(1, 0, 1))
						:vectorToObjectSpace(Humanoid.MoveDirection)

				NewPush = NewPush + ((ForwardVector * CameraSpeed.Z * -localControlVector.z) or NewPush)
				NewPush = NewPush + ((SideVector * CameraSpeed.X * -localControlVector.x) or NewPush)

				--NewPush = (NewPush + (((Controls.Forward.Mode and not Controls.Backward.Mode) and (ForwardVector * CameraSpeed.Z)) or ((not Controls.Forward.Mode and Controls.Backward.Mode) and (ForwardVector * CameraSpeed.Z * -1)) or NewPush))
				--NewPush = (NewPush + (((Controls.Left.Mode and not Controls.Right.Mode) and (SideVector * CameraSpeed.X)) or ((not Controls.Left.Mode and Controls.Right.Mode) and (SideVector * CameraSpeed.X * -1)) or NewPush))
				FlightSpin.cframe = CFrame.new(Vector3.new(0, 0, 0), ForwardVector)
				if NewPush.magnitude < 1 then
					FlightHold.maxForce = Vector3.new((FlightHold.P * 100), (FlightHold.P * 100), (FlightHold.P * 100))
					FlightPower.maxForce = Vector3.new(0, 0, 0)
					if IsMoving then
						FlightHold.position = Torso.Position
					end
					IsMoving = false
				else
					IsMoving = true
					FlightHold.maxForce = Vector3.new(0, 0, 0)
					FlightPower.maxForce =
						Vector3.new((FlightPower.P * 100), (FlightPower.P * 100), (FlightPower.P * 100))
				end
				FlightPower.velocity = NewPush
				wait(Rate)
			end
			Flying = false
			if CheckIfAlive() then
				Torso.Velocity = Vector3.new(0, 0, 0)
				Torso.RotVelocity = Vector3.new(0, 0, 0)
				Humanoid.WalkSpeed = 16
				Humanoid.PlatformStand = false
				Humanoid.AutoRotate = true
				DisableJump(false)
				Humanoid:ChangeState(Enum.HumanoidStateType.Freefall)
			end
		end
	end)
end

function SetAnimation(mode, value)
	if mode == "PlayAnimation" and value and ToolEquipped and Humanoid then
		for i, v in pairs(Animations) do
			if v.Animation == value.Animation then
				v.AnimationTrack:Stop()
				table.remove(Animations, i)
			end
		end
		local AnimationTrack = Humanoid:LoadAnimation(value.Animation)
		table.insert(Animations, { Animation = value.Animation, AnimationTrack = AnimationTrack })
		AnimationTrack:Play(value.FadeTime, value.Weight, value.Speed)
	elseif mode == "StopAnimation" and value then
		for i, v in pairs(Animations) do
			if v.Animation == value.Animation then
				v.AnimationTrack:Stop()
				table.remove(Animations, i)
			end
		end
	end
end

function DisableJump(Boolean)
	if PreventJump then
		PreventJump:disconnect()
	end
	if Boolean then
		PreventJump = Humanoid.Changed:connect(function(Property)
			if Property == "Jump" then
				Humanoid.Jump = false
			end
		end)
	end
end

function CheckIfAlive()
	return (
		(
			(
				Character
				and Character.Parent
				and Humanoid
				and Humanoid.Parent
				and Humanoid.Health > 0
				and Torso
				and Torso.Parent
				and Player
				and Player.Parent
			) and true
		) or false
	)
end

function KeyPress(Key, Down)
	local Key = string.lower(Key)
	local ByteKey = string.byte(Key)
	for i, v in pairs(Controls) do
		if Key == v.Keys.Key or ByteKey == v.Keys.ByteKey then
			Controls[i].Mode = Down
		end
	end
end

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	Torso = Character:FindFirstChild("HumanoidRootPart")
	ToolEquipped = true
	if not CheckIfAlive() then
		return
	end
	Mouse.KeyDown:connect(function(Key)
		KeyPress(Key, true)
	end)
	Mouse.KeyUp:connect(function(Key)
		KeyPress(Key, false)
	end)
	Spawn(HandleFlightControl)
end

function Unequipped()
	Flying = false
	LocalObjects = {}
	for i, v in pairs(Animations) do
		if v and v.AnimationTrack then
			v.AnimationTrack:Stop()
		end
	end
	for i, v in pairs({ PreventJump, FightMonitor }) do
		if v then
			v:disconnect()
		end
	end
	for i, v in pairs(Controls) do
		Controls[i].Mode = false
	end
	Animations = {}
	ToolEquipped = false
end

function InvokeServer(mode, value)
	local ServerReturn
	pcall(function()
		ServerReturn = ServerControl:InvokeServer(mode, value)
	end)
	return ServerReturn
end

function OnClientInvoke(mode, value)
	if mode == "PlayAnimation" and value and ToolEquipped and Humanoid then
		SetAnimation("PlayAnimation", value)
	elseif mode == "StopAnimation" and value then
		SetAnimation("StopAnimation", value)
	elseif mode == "PlaySound" and value then
		value:Play()
	elseif mode == "StopSound" and value then
		value:Stop()
	end
end

ClientControl.OnClientInvoke = OnClientInvoke
Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)
