Aircraft Local Script vs Script Hassle

Hello
I am working on a dogfight minigame in my game SpaceWars.
However, my main script for the planes are in a local script for each one…
So this means when I shoot someone witht he gun, they die on my screen, but they are perfectly fine on their’s.
Here is my code.

repeat wait() until game.Players.LocalPlayer
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Plane = Character.Plane
local AutoCrash = Plane.AutoCrash
local Weapons = Plane.Weapons
local MainParts = Plane.MainParts
local Gear = MainParts.Gear
local Engine = MainParts.Engine
local Thrust = Engine.Thrust
local Direction = Engine.Direction
local Customize = Plane.Customize
local Tool = script.Parent
local GUI = Tool.PlaneGui
local ToolSelect = Tool.ToolSelect
local Deselect0 = Tool.Deselect0
local FireMain = Tool.FireMain
local Camera = game.Workspace.CurrentCamera
local RunService = game:GetService("RunService")
local Acceleration = Customize.Acceleration
local MaxSpeed = Customize.MaxSpeed
local StallSpeed = Customize.StallSpeed
local TurnSpeed = Customize.TurnSpeed
local ThrottleInc = Customize.ThrottleInc
local MaxBank = Customize.MaxBank
local CameraType = Customize.CameraType
local CamLock = Customize.CamLock
local HUDOnLock = Customize.HUDOnLock
local Ejectable = Customize.Ejectable
local PlaneName = Customize.PlaneName
local Targetable = Customize.Targetable
local FlightControls = Customize.FlightControls
local WeaponControls = Customize.WeaponControls
local TargetControls = Customize.TargetControls
local WeaponsValue = Customize.Weapons
local ReloadTimes = Customize.ReloadTimes
local AltRestrict = Customize.AltitudeRestrict
local MaxAltitude = AltRestrict.MaxAltitude
local MinAltitude = AltRestrict.MinAltitude
local GuiAVisible = true
local GuiBVisible = true
local BombM = FireMain.BombM
local MissileM = FireMain.MissileM
local RocketEnabled = true
local FlareEnabled = true
local BombEnabled = true
local MissileEnabled = true
local SUAK = false
local SDAK = false
local EngineOn = false
local Selected = false
local LockedCam = false
local LowestPoint = 0
local DesiredSpeed = 0
local CurrentSpeed = 0
local TrueAirSpeed = 0
local Throttle = 0
local FTab = {nil,nil,nil,nil,nil,nil,nil}
local LockGui = nil
local AimGui = nil
local TargetPlayer = nil
local Locked = false
local Targeting = false
local AimingCursor = "http://www.roblox.com/asset/?id=107455536"
local LockedCursor = "http://www.roblox.com/asset/?id=107455986"
local TargetCursor = "http://www.roblox.com/asset/?id=107455960"
local NormalCursor = "http://www.roblox.com/asset/?id=116176885"
local LandingGear = {}
local GearUp = false

function FixVars()
	Acceleration2 = (Acceleration.Value < 0 and 0 or Acceleration.Value > 1000 and 1000 or Acceleration.Value)
	MaxBank2 = (MaxBank.Value < -90 and -90 or MaxBank.Value > 90 and 90 or MaxBank.Value)
	MaxSpeed2 = (MaxSpeed.Value < 0 and 0 or MaxSpeed.Value < StallSpeed.Value and StallSpeed.Value or MaxSpeed.Value)
	StallSpeed2 = (StallSpeed.Value < 0 and 0 or StallSpeed.Value > MaxSpeed.Value and MaxSpeed.Value or StallSpeed.Value)
	TurnSpeed2 = (TurnSpeed.Value < 0 and 0 or TurnSpeed.Value)
	ThrottleInc2 = (ThrottleInc.Value < 0 and 0 or ThrottleInc.Value)
	MaxAltitude2 = (MaxAltitude.Value < MinAltitude.Value and MinAltitude.Value or MaxAltitude.Value)
	MinAltitude2 = (MinAltitude.Value > MaxAltitude.Value and MaxAltitude.Value or MinAltitude.Value)
	MissileTime2 = (ReloadTimes.Missiles.Value < 0 and 0 or ReloadTimes.Missiles.Value)
	RocketTime2 = (ReloadTimes.Rockets.Value < 0 and 0 or ReloadTimes.Rockets.Value)
	GunTime2 = (ReloadTimes.Guns.Value < 0 and 0 or ReloadTimes.Guns.Value)
	FlareTime2 = (ReloadTimes.Flares.Value < 0 and 0 or ReloadTimes.Flares.Value)
	BombTime2 = (ReloadTimes.Bombs.Value < 0 and 0 or ReloadTimes.Bombs.Value)
	CameraType2 = (pcall(function() Camera.CameraType = CameraType.Value end) and CameraType.Value or "Custom")
	PlaneName2 = (PlaneName.Value == "" and "Plane" or PlaneName.Value)
	if WeaponsValue.Value then
		if WeaponsValue.Missiles.Value or WeaponsValue.Bombs.Value then
			Targetable2 = true
		elseif (not (WeaponsValue.Missiles.Value and WeaponsValue.Bombs.Value)) then
			Targetable2 = false
		end
	elseif (not WeaponsValue.Value) then
		Targetable2 = false
	end
	if FlightControls.SpeedUp.Value == "ArrowKeyUp" then
		SpeedUp2 = 17
		SUAK = true
	elseif FlightControls.SpeedUp.Value == "ArrowKeyDown" then
		SpeedUp2 = 18
		SUAK = true
	else
		SpeedUp2 = FlightControls.SpeedUp.Value
		SUAK = false
	end
	if FlightControls.SlowDown.Value == "ArrowKeyUp" then
		SlowDown2 = 17
		SDAK = true
	elseif FlightControls.SlowDown.Value == "ArrowKeyDown" then
		SlowDown2 = 18
		SDAK = true
	else
		SlowDown2 = FlightControls.SlowDown.Value
		SDAK = false
	end
	Engine.Direction.P = TurnSpeed2
end

function FireMachineGun(GunParent)
	while FiringGun do
		for _,v in pairs(GunParent:GetChildren()) do
			if v:IsA("BasePart") then
				if v.Name == "MachineGun" then
					local Part = Instance.new("Part")
					Part.BrickColor = BrickColor.new("Really red")
					Part.Name = "Bullet"
					Part.CanCollide = false
					Part.FormFactor = "Symmetric"
					Part.Size = Vector3.new(5,5,3)
					Part.BottomSurface = "Smooth"
					Part.TopSurface = "Smooth"
					local Mesh = Instance.new("BlockMesh")
					Mesh.Parent = Part
					Mesh.Scale = Vector3.new(1/25,1/25,1)
					local BV = Instance.new("BodyVelocity")
					BV.Parent = Part
					BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
					local PlaneTag = Instance.new("ObjectValue")
					PlaneTag.Parent = Part
					PlaneTag.Name = "PlaneTag"
					PlaneTag.Value = Plane
					Part.Touched:connect(function(Object)
						if (not Object:IsDescendantOf(Character)) then
							local HitHumanoid = Object.Parent:findFirstChild("Humanoid")
							if HitHumanoid then
								HitHumanoid:TakeDamage(100)
								local CreatorTag = Instance.new("ObjectValue")
								CreatorTag.Name = "creator"
								CreatorTag.Value = Player
								CreatorTag.Parent = HitHumanoid
							elseif (not HitHumanoid) and Object.Name ~= "SpawnLocation" and Object.Name ~= "Main" and Object.Name ~= "Platiform" then
								print("Steel Inquisitor is curious about this issue.")
								Object:Destroy()
							end
						end
					end)
					Part.Parent = game.Workspace
					Part.CFrame = v.CFrame + v.CFrame.lookVector * 10
					BV.velocity = (v.Velocity) + (Part.CFrame.lookVector * 2000) + (Vector3.new(0,0.15,0))
					delay(3,function() Part:Destroy() end)
				end
			end
		end
		wait(GunTime2)
	end
end

function FireRockets(GunParent)
	for _,v in pairs(GunParent:GetChildren()) do
		if v:IsA("BasePart") then
			if v.Name == "RocketSpawn" then
				local Exploded = false
				local Part1 = Instance.new("Part")
				Part1.BrickColor = BrickColor.new("White")
				Part1.Name = "Missile"
				Part1.CanCollide = false
				Part1.FormFactor = "Symmetric"
				Part1.Size = Vector3.new(1,1,5)
				Part1.BottomSurface = "Smooth"
				Part1.TopSurface = "Smooth"
				local Mesh = Instance.new("SpecialMesh")
				Mesh.Parent = Part1
				Mesh.MeshId = "http://www.roblox.com/asset/?id=2251534"
				Mesh.MeshType = "FileMesh"
				Mesh.Scale = Vector3.new(0.5,0.5,0.5)
				local Part2 = Instance.new("Part")
				Part2.Parent = Part1
				Part2.Transparency = 1
				Part2.Name = "Visual"
				Part2.CanCollide = false
				Part2.FormFactor = "Symmetric"
				Part2.Size = Vector3.new(1,1,1)
				Part2.BottomSurface = "Smooth"
				Part2.TopSurface = "Smooth"
				local Weld = Instance.new("Weld")
				Weld.Parent = Part1
				Weld.Part0 = Part1
				Weld.Part1 = Part2
				Weld.C0 = CFrame.new(0,0,4) * CFrame.Angles(math.rad(90),0,0)
				local BV = Instance.new("BodyVelocity")
				BV.Parent = Part1
				BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
				local BG = Instance.new("BodyGyro")
				BG.Parent = Part
				BG.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
				BG.cframe = v.CFrame
				local Fire = Instance.new("Fire")
				Fire.Parent = Part2
				Fire.Heat = 25
				Fire.Size = 10
				local Smoke = Instance.new("Smoke")
				Smoke.Parent = Part2
				Smoke.Color = Color3.new(200/255,200/255,200/255)
				Smoke.Opacity = 0.7
				Smoke.RiseVelocity = 25
				Smoke.Size = 10
				local PlaneTag = Instance.new("ObjectValue")
				PlaneTag.Parent = Part
				PlaneTag.Name = "PlaneTag"
				PlaneTag.Value = Plane
				Part1.Touched:connect(function(Object)
					if (not Exploded) then
						if (not Object:IsDescendantOf(Character)) then
							if Object.Name ~= "Missile" then
								Exploded = true
								local Explosion = Instance.new("Explosion",game.Workspace)
								Explosion.Position = Part1.Position
								Explosion.BlastPressure = 5000
								Explosion.BlastRadius = 25
								ScanPlayers(Part1.Position,25)
								Explosion.Parent = game.Workspace
								Part1:Destroy()
							end
						end
					end
				end)
				Part1.Parent = game.Workspace
				Part1.CFrame = v.CFrame + v.CFrame.lookVector * 10
				BV.velocity = Part1.CFrame.lookVector * 1250 + Vector3.new(0,0.15,0)
				delay(5,function() Part1:Destroy() end)
			end
		end
	end
end

function DeployFlares(GunParent)
	for _,v in pairs(GunParent:GetChildren()) do
		if v:IsA("BasePart") then
			if v.Name == "FlareSpawn" then
				local RandomFactor = 40
				local RandomX = math.rad(math.random(-RandomFactor,RandomFactor))
				local RandomY = math.rad(math.random(-RandomFactor,RandomFactor))
				local Part = Instance.new("Part")
				Part.Transparency = 1
				Part.Name = "Flare"
				Part.CanCollide = false
				Part.FormFactor = "Symmetric"
				Part.Size = Vector3.new(1,1,1)
				Part.BottomSurface = "Smooth"
				Part.TopSurface = "Smooth"
				local BG = Instance.new("BillboardGui")
				BG.Parent = Part
				BG.Size = UDim2.new(10,0,10,0)
				local IL = Instance.new("ImageLabel")
				IL.Parent = BG
				IL.BackgroundTransparency = 1
				IL.Image = "http://www.roblox.com/asset/?id=43708803"
				IL.Size = UDim2.new(1,0,1,0)
				local Smoke = Instance.new("Smoke")
				Smoke.Parent = Part
				Smoke.Opacity = 0.5
				Smoke.RiseVelocity = 25
				Smoke.Size = 5
				local PL = Instance.new("PointLight")
				PL.Parent = Part
				PL.Brightness = 10
				PL.Color = Color3.new(1,1,0)
				PL.Range = 20
				Part.Parent = game.Workspace
				Part.CFrame = (v.CFrame + v.CFrame.lookVector * 5) * CFrame.Angles(RandomX,RandomY,0)
				Part.Velocity = Part.CFrame.lookVector * 150
				delay(5,function() Part:Destroy() end)
			end
		end
	end
end

function DropBomb(GunParent)
	if (not Locked) then
		for _,v in pairs(GunParent:GetChildren()) do
			if v:IsA("BasePart") then
				if v.Name == "BombSpawn" then
					local Exploded = false
					local Part = Instance.new("Part")
					Part.Name = "Bomb"
					Part.CanCollide = false
					Part.FormFactor = "Symmetric"
					Part.Size = Vector3.new(2,2,9)
					Part.BottomSurface = "Smooth"
					Part.TopSurface = "Smooth"
					local Mesh = Instance.new("SpecialMesh")
					Mesh.Parent = Part
					Mesh.MeshId = "http://www.roblox.com/asset/?id=88782666"
					Mesh.MeshType = "FileMesh"
					Mesh.Scale = Vector3.new(4,4,4)
					Mesh.TextureId = "http://www.roblox.com/asset/?id=88782631"
					local BG = Instance.new("BodyGyro")
					BG.Parent = Part
					BG.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
					BG.cframe = v.CFrame * CFrame.Angles(math.rad(90),0,0)
					local PlaneTag = Instance.new("ObjectValue")
					PlaneTag.Parent = Part
					PlaneTag.Name = "PlaneTag"
					PlaneTag.Value = Plane
					Part.Touched:connect(function(Object)
						if (not Exploded) then
							if (not Object:IsDescendantOf(Character)) and Object.Name ~= "Bomb" then
								Exploded = true
								local Explosion = Instance.new("Explosion")
								Explosion.Position = Part.Position
								Explosion.BlastPressure = 500000
								Explosion.BlastRadius = 25
								ScanPlayers(Part.Position,25)
								Explosion.Parent = game.Workspace
								Part:Destroy()
							end
						end
					end)
					Part.Parent = game.Workspace
					Part.CFrame = (v.CFrame * CFrame.Angles(math.rad(90),0,0)) + v.CFrame.lookVector * 3
					Part.Velocity = (Part.CFrame.lookVector * (TrueAirSpeed * 0.75))
					delay(7,function() Part:Destroy() end)
				end
			end
		end
	end
end

function DropGuidedBomb(Gun)
	if Locked then
		local Exploded = false
		local Part = Instance.new("Part")
		Part.Name = "Bomb"
		Part.CanCollide = false
		Part.FormFactor = "Symmetric"
		Part.Size = Vector3.new(2,2,9)
		Part.BottomSurface = "Smooth"
		Part.TopSurface = "Smooth"
		local Mesh = Instance.new("SpecialMesh")
		Mesh.Parent = Part
		Mesh.MeshId = "http://www.roblox.com/asset/?id=88782666"
		Mesh.MeshType = "FileMesh"
		Mesh.Scale = Vector3.new(4,4,4)
		Mesh.TextureId = "http://www.roblox.com/asset/?id=88782631"
		local OV = Instance.new("ObjectValue")
		OV.Parent = Part
		OV.Name = "Tracker"
		OV.Value = TargetPlayer.Character.Torso
		local NV = Instance.new("NumberValue")
		NV.Parent = Part
		NV.Name = "PlaneSpd"
		NV.Value = TrueAirSpeed * 0.8
		local BG = Instance.new("BodyGyro")
		BG.Parent = Part
		BG.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
		BG.P = 2000
		local BV = Instance.new("BodyVelocity")
		BV.Parent = Part
		BV.maxForce = Vector3.new(math.huge,6000,math.huge)
		BV.velocity = Vector3.new(0,0,0)
		local Script = BombM:clone()
		Script.Parent = Part
		local PlaneTag = Instance.new("ObjectValue")
		PlaneTag.Parent = Part
		PlaneTag.Name = "PlaneTag"
		PlaneTag.Value = Plane
		Part.Touched:connect(function(Object)
			if (not Exploded) then
				if (not Object:IsDescendantOf(Character)) and Object.Name ~= "Bomb" then
					Exploded = true
					local Explosion = Instance.new("Explosion")
					Explosion.Position = Part.Position
					Explosion.BlastPressure = 500000
					Explosion.BlastRadius = 25
					ScanPlayers(Part.Position,25)
					Explosion.Parent = game.Workspace
					Part:Destroy()
				end
			end
		end)
		Part.Parent = game.Workspace
		Part.CFrame = (Gun.CFrame * CFrame.Angles(math.rad(90),0,0)) + Gun.CFrame.lookVector * 10
		Script.Disabled = false
	end
end

function FireMissile(Gun)
	if (not Locked) then
		local Exploded = false
		local Part1 = Instance.new("Part")
		Part1.Name = "Missile"
		Part1.CanCollide = false
		Part1.FormFactor = "Symmetric"
		Part1.Size = Vector3.new(1,1,13)
		Part1.BottomSurface = "Smooth"
		Part1.TopSurface = "Smooth"
		local Mesh = Instance.new("SpecialMesh")
		Mesh.Parent = Part1
		Mesh.MeshId = "http://www.roblox.com/asset/?id=2251534"
		Mesh.MeshType = "FileMesh"
		Mesh.TextureId = "http://www.roblox.com/asset/?id=2564491"
		local Part2 = Instance.new("Part")
		Part2.Parent = Part1
		Part2.Name = "Visual"
		Part2.Transparency = 1
		Part2.CanCollide = false
		Part2.FormFactor = "Symmetric"
		Part2.Size = Vector3.new(1,1,1)
		Part2.BottomSurface = "Smooth"
		Part2.TopSurface = "Smooth"
		local Weld = Instance.new("Weld")
		Weld.Parent = Part1
		Weld.Part0 = Part1
		Weld.Part1 = Part2
		Weld.C0 = CFrame.new(0,0,5)*CFrame.Angles(math.rad(90),0,0)
		local BV = Instance.new("BodyVelocity")
		BV.Parent = Part1
		BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
		local BG = Instance.new("BodyGyro")
		BG.Parent = Part
		BG.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
		BG.cframe = Gun.CFrame * CFrame.Angles(math.rad(90),0,0)
		local Fire = Instance.new("Fire")
		Fire.Parent = Part2
		Fire.Enabled = false
		Fire.Heat = 25
		Fire.Size = 30
		local Smoke = Instance.new("Smoke")
		Smoke.Parent = Part2
		Smoke.Color = Color3.new(40/51,40/51,40/51)
		Smoke.Enabled = false
		Smoke.Opacity = 1
		Smoke.RiseVelocity = 25
		Smoke.Size = 25
		local PlaneTag = Instance.new("ObjectValue")
		PlaneTag.Parent = Part
		PlaneTag.Name = "PlaneTag"
		PlaneTag.Value = Plane
		Part1.Touched:connect(function(Object)
			if (not Exploded) then
				if (not Object:IsDescendantOf(Character)) and Object.Name ~= "Missile" then
					Exploded = true
					local Explosion = Instance.new("Explosion")
					Explosion.Position = Part1.Position
					Explosion.BlastPressure = 50000
					Explosion.BlastRadius = 25
					ScanPlayers(Part1.Position,25)
					Explosion.Parent = game.Workspace
					Part1:Destroy()
				end
			end
		end)
		Part1.Parent = game.Workspace
		Part1.CFrame = (Gun.CFrame * CFrame.Angles(math.rad(90),0,0)) + Gun.CFrame.lookVector * 15
		BV.velocity = Part1.CFrame.lookVector * Engine.Velocity.magnitude
		delay(0.3,function()
			BV.velocity = (Part1.CFrame.lookVector * 1500) + Vector3.new(0,0.15,0)
			Fire.Enabled = true
			Smoke.Enabled = true
		end)
		delay(5,function() Part1:Destroy() end)
	end
end

function FireGuidedMissile(Gun)
	if Targetable2 then
		if Locked then
			local Exploded = false
			local Part1 = Instance.new("Part")
			Part1.Name = "Missile"
			Part1.CanCollide = false
			Part1.FormFactor = "Symmetric"
			Part1.Size = Vector3.new(1,1,13)
			Part1.BottomSurface = "Smooth"
			Part1.TopSurface = "Smooth"
			local Mesh = Instance.new("SpecialMesh")
			Mesh.Parent = Part1
			Mesh.MeshId = "http://www.roblox.com/asset/?id=2251534"
			Mesh.MeshType = "FileMesh"
			Mesh.TextureId = "http://www.roblox.com/asset/?id=2564491"
			local Part2 = Instance.new("Part")
			Part2.Parent = Part1
			Part2.Transparency = 1
			Part2.Name = "Visual"
			Part2.CanCollide = false
			Part2.FormFactor = "Symmetric"
			Part2.Size = Vector3.new(1,1,1)
			Part2.BottomSurface = "Smooth"
			Part2.TopSurface = "Smooth"
			local Weld = Instance.new("Weld")
			Weld.Parent = Part1
			Weld.Part0 = Part1
			Weld.Part1 = Part2
			Weld.C0 = CFrame.new(0,0,5)*CFrame.Angles(math.rad(90),0,0)
			local OV = Instance.new("ObjectValue")
			OV.Parent = Part1
			OV.Name = "Tracker"
			OV.Value = TargetPlayer.Character.Torso
			local BV = Instance.new("BodyVelocity")
			BV.Parent = Part1
			BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
			local Script = MissileM:clone()
			Script.Parent = Part1
			local Fire = Instance.new("Fire")
			Fire.Parent = Part2
			Fire.Enabled = false
			Fire.Heat = 25
			Fire.Size = 30
			local Smoke = Instance.new("Smoke")
			Smoke.Parent = Part2
			Smoke.Color = Color3.new(40/51,40/51,40/51)
			Smoke.Enabled = false
			Smoke.Opacity = 1
			Smoke.RiseVelocity = 25
			Smoke.Size = 25
			local PlaneTag = Instance.new("ObjectValue")
			PlaneTag.Parent = Part
			PlaneTag.Name = "PlaneTag"
			PlaneTag.Value = Plane
			Part1.Touched:connect(function(Object)
				if (not Exploded) then
					if (not Object:IsDescendantOf(Character)) and Object.Name ~= "Missile" then
						Exploded = true
						local Explosion = Instance.new("Explosion")
						Explosion.Position = Part1.Position
						Explosion.BlastPressure = 50000
						Explosion.BlastRadius = 25
						ScanPlayers(Part1.Position,25)
						Explosion.Parent = game.Workspace
						Part1:Destroy()
					end
				end
			end)
			Part1.Parent = game.Workspace
			Part1.CFrame = (Gun.CFrame * CFrame.Angles(math.rad(90),0,0)) + Gun.CFrame.lookVector * 15
			delay(0.3,function()
				Script.Disabled = false
				Fire.Enabled = true
				Smoke.Enabled = true
			end)
			delay(10,function() Part1:Destroy() end)
		end
	end
end

function ScanPlayers(Pos,Radius)
	coroutine.resume(coroutine.create(function()
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.Character and v.Character:findFirstChild("Torso") then
				local PTorso = v.Character.Torso
				if ((PTorso.Position - Pos).magnitude + 2) <= Radius then
					local HitHumanoid = v.Character:findFirstChild("Humanoid")
					if HitHumanoid then
						local CreatorTag = Instance.new("ObjectValue")
						CreatorTag.Name = "creator"
						CreatorTag.Value = Player
						CreatorTag.Parent = HitHumanoid
						game:GetService("Debris"):AddItem(CreatorTag,0.1)
					end
				end
			end
		end
	end))
end

function ReloadRocket(Time)
	if (not RocketEnabled) then
		wait(Time)
		RocketEnabled = true
	end
end

function ReloadFlare(Time)
	if (not FlareEnabled) then
		wait(Time)
		FlareEnabled = true
	end
end

function ReloadBomb(Time)
	if (not BombEnabled) then
		wait(Time)
		BombEnabled = true
	end
end

function ReloadMissile(Time)
	if (not MissileEnabled) then
		wait(Time)
		MissileEnabled = true
	end
end

function onMouseMoved(mouse)
	if Targetable2 then
		local Gui = GuiClone.Main
		if Targeting then
			mouse.Icon = AimingCursor
			Gui.Mode.Text = "Targeting Mode"
			local FoundPlayer = false
			for i,v in pairs(game.Players:GetPlayers()) do
				if v.Character then
					if v.Character:findFirstChild("Torso") then
						if v ~= Player then
							if ((v.TeamColor ~= Player.TeamColor) or v.Neutral) then
								local myHead = Character.Head
								local TorsoPos = v.Character.Torso.CFrame
								local Distance = (myHead.CFrame.p - TorsoPos.p).magnitude
								local MouseDirection = (mouse.Hit.p - myHead.CFrame.p).unit
								local Offset = (((MouseDirection * Distance) + myHead.CFrame.p) - TorsoPos.p).magnitude
								if (not Locked) then
									if (Offset/Distance) < 0.1 then
										FoundPlayer = true
										if TargetPlayer ~= v then
											TargetPlayer = v
											mouse.Icon = TargetCursor
											AimGui.Enabled = true
											LockGui.Enabled = false
											AimGui.Adornee = TargetPlayer.Character.Torso
											LockGui.Adornee = nil
										end
									end
									if (not FoundPlayer) and TargetPlayer then
										TargetPlayer = nil
										mouse.Icon = AimingCursor
										AimGui.Enabled = false
										LockGui.Enabled = false
										AimGui.Adornee = nil
										LockGui.Adornee = nil
									end
								elseif Locked then
									mouse.Icon = LockedCursor
									AimGui.Enabled = false
									LockGui.Enabled = true
									AimGui.Adornee = nil
									LockGui.Adornee = TargetPlayer.Character.Torso
								end
							end
						end
					end
				end
			end
		elseif (not Targeting) then
			mouse.Icon = NormalCursor
			Gui.Mode.Text = "Flying Mode"
		end
	end
end

function onButton1Down(mouse)
	Locked = ((not Locked) and TargetPlayer and Targeting and EngineOn and Targeting2)
end

function IncreaseSpd()
	if EngineOn then
		if Selected then
			while Accelerating do
				Throttle = (Throttle < 1 and Throttle + 0.01 or 1)
				DesiredSpeed = MaxSpeed2 * Throttle
				wait(ThrottleInc2)
			end
		end
	end
end

function DecreaseSpd()
	if EngineOn then
		if Selected then
			while Decelerating do
				Throttle = (Throttle > 0 and Throttle - 0.01 or 0)
				DesiredSpeed = MaxSpeed2 * Throttle
				wait(ThrottleInc2)
			end
		end
	end
end

function RoundNumber(Num)
	return ((Num - math.floor(Num)) >= 0.5 and math.ceil(Num) or math.floor(Num))
end

function GetGear(Parent)
	for i,v in pairs(Parent:GetChildren()) do
		if (v:IsA("BasePart")) then
			if (not v:findFirstChild("GearProp")) then
				local GearProp = Instance.new("StringValue")
				GearProp.Name = "GearProp"
				GearProp.Value = v.Transparency..","..tostring(v.CanCollide)
				GearProp.Parent = v
			end
			table.insert(LandingGear,v)
		end
		GetGear(v)
	end
end

function ChangeGear()
	for i,v in pairs(LandingGear) do
		local GearProp = v.GearProp
		local Comma = GearProp.Value:find(",",1,true)
		local TransVal = tonumber(GearProp.Value:sub(1,Comma - 1))
		local CollideVal = GearProp.Value:sub(Comma + 1)
		v.Transparency = (TransVal ~= 1 and (GearUp and TransVal or 1))
		v.CanCollide = (CollideVal and (GearUp and CollideVal or false))
	end
end

function SetUpGui()
	local Gui = GuiClone.Main
	Gui.Title.Text = PlaneName2
	local TargetStats = Gui.Parent.Target
	local HUD = Gui.Parent.HUD
	local ControlsA,ControlsB = Gui.ControlsA,Gui.ControlsB
	local FrameA,FrameB = Gui.FrameA,Gui.FrameB
	local C1A,C1B = FrameA.C1.Key,FrameB.C1.Key
	local C2A,C2B = FrameA.C2.Key,FrameB.C2.Key
	local C3A,C3B = FrameA.C3.Key,FrameB.C3.Key
	local C4A,C4B = FrameA.C4.Key,FrameB.C4.Key
	local C5A,C5B = FrameA.C5.Key,FrameB.C5.Key
	local C6,C7 = FrameA.C6.Key,FrameA.C7.Key
	local GearText = Gui.Gear
	for i,v in pairs(LandingGear) do
		if v.Transparency == 1 then
			GearUp = true
		else
			GearUp = false
			break
		end
	end
	local MaxSpeedScaled = math.ceil(MaxSpeed2/50)
	for i = 1,(MaxSpeedScaled + 10) do
		local SpeedGui = HUD.Speed.Main
		local Speed0 = SpeedGui["Speed-0"]
		local SpeedClone = Speed0:clone()
		SpeedClone.Position = UDim2.new(0,0,1,-(80 + (75 * i)))
		SpeedClone.Name = ("Speed-%i"):format(50 * i)
		SpeedClone.Text.Text = tostring(50 * i)
		SpeedClone.Parent = SpeedGui
	end
	local MaxAltScaled = math.ceil(MaxAltitude2/500)
	for i = 1,(MaxAltScaled + 10) do
		local AltGui = HUD.Altitude.Main
		local Altitude0 = AltGui["Altitude-0"]
		local AltClone = Altitude0:clone()
		AltClone.Position = UDim2.new(0,0,1,-(80 + (75 * i)))
		AltClone.Name = ("Altitude-%s"):format(tostring(0.5 * i))
		AltClone.Text.Text = tostring(0.5 * i)
		AltClone.Parent = AltGui
	end
	GearText.Text = (GearUp and "Gear Up" or "Gear Down")
	C1A.Text = "Key: "..FlightControls.Engine.Value:upper()
	if FlightControls.SpeedUp.Value == "ArrowKeyUp" then
		C2A.Text = "Key: ArrowKeyUp"
	elseif FlightControls.SpeedUp.Value == "ArrowKeyDown" then
		C2A.Text = "Key: ArrowKeyDown"
	else
		C2A.Text = "Key: "..FlightControls.SpeedUp.Value:upper()
	end
	if FlightControls.SlowDown.Value == "ArrowKeyUp" then
		C3A.Text = "Key: ArrowKeyUp"
	elseif FlightControls.SlowDown.Value == "ArrowKeyDown" then
		C3A.Text = "Key: ArrowKeyDown"
	else
		C3A.Text = "Key: "..FlightControls.SlowDown.Value:upper()
	end
	C4A.Text = "Key: "..FlightControls.Gear.Value:upper()
	if Targetable2 then
		C5A.Text = "Key: "..TargetControls.Modes.Value:upper()
	else
		C5A.Parent.Visible = false
	end
	if Ejectable.Value then
		C6.Text = "Key: "..FlightControls.Eject.Value:upper()
	else
		C6.Parent.Visible = false
	end
	if CamLock.Value then
		C7.Text = "Key: "..FlightControls.LockCam.Value:upper()
	else
		C7.Parent.Visible = false
	end
	if (not WeaponsValue.Value) then
		C1B.Parent.Visible = false
		C2B.Parent.Visible = false
		C3B.Parent.Visible = false
		C4B.Parent.Visible = false
		C5B.Parent.Visible = false
		FrameB.Title.Text = "No Weapons"
	elseif WeaponsValue.Value then
		if WeaponsValue.Missiles.Value then
			C1B.Text = "Key: "..WeaponControls.FireMissile.Value:upper()
		elseif (not WeaponsValue.Missiles.Value) then
			C1B.Parent.Visible = false
		end
		if WeaponsValue.Rockets.Value then
			C2B.Text = "Key: "..WeaponControls.FireRockets.Value:upper()
		elseif (not WeaponsValue.Rockets.Value) then
			C2B.Parent.Visible = false
		end
		if WeaponsValue.Guns.Value then
			C3B.Text = "Key: "..WeaponControls.FireGuns.Value:upper()
		elseif (not WeaponsValue.Guns.Value) then
			C3B.Parent.Visible = false
		end
		if WeaponsValue.Bombs.Value then
			C4B.Text = "Key: "..WeaponControls.DropBombs.Value:upper()
		elseif (not WeaponsValue.Bombs.Value) then
			C4B.Parent.Visible = false
		end
		if WeaponsValue.Flares.Value then
			C5B.Text = "Key: "..WeaponControls.DeployFlares.Value:upper()
		elseif (not WeaponsValue.Flares.Value) then
			C5B.Parent.Visible = false
		end
	end
	ControlsA.MouseButton1Click:connect(function()		if GuiAVisible then
			GuiAVisible = false
			FrameA:TweenPosition(UDim2.new(0,150,0,-190),"In","Quad",1,true)
		elseif (not GuiAVisible) then
			GuiAVisible = true
			FrameA:TweenPosition(UDim2.new(0,150,0,170),"Out","Quad",1,true)
		end
	end)
	ControlsB.MouseButton1Click:connect(function()
		if GuiBVisible then
			GuiBVisible = false
			FrameB:TweenPosition(UDim2.new(0,-150,0,-150),"In","Quad",1,true)
		elseif (not GuiBVisible) then
			GuiBVisible = true
			FrameB:TweenPosition(UDim2.new(0,-150,0,170),"Out","Quad",1,true)
		end
	end)
end

function GetRoll(CF)	local CFRight = CF * CFrame.Angles(0,math.rad(90),0)
	local CFNoRollRight = CFrame.new(CF.p,CF.p + CF.lookVector) * CFrame.Angles(0,math.rad(90),0)
	local CFDiff = CFRight:toObjectSpace(CFNoRollRight)
	return (-math.atan2(CFDiff.lookVector.Y, CFDiff.lookVector.Z) % (math.pi * 2) + math.pi)
end

function GetPitch(CF)	local LV = CF.lookVector
	local XZDist = math.sqrt(LV.x^2 + LV.z^2)
	return math.atan(LV.y / XZDist)
end

function UpdateCamera()	if Selected then
		if (not LockedCam) then
			Camera.CameraType = CameraType2
		elseif LockedCam then
			local HeadCF = Character.Head.CFrame
			local PlaneSize = Plane:GetModelSize().magnitude/3
			local Origin = HeadCF.p + (HeadCF.lookVector * (PlaneSize - 1))
			local Target = HeadCF.p + (HeadCF.lookVector * PlaneSize)
			Camera.CameraType = Enum.CameraType.Scriptable
			Camera.CoordinateFrame = CFrame.new(Origin,Target)
			Camera:SetRoll(GetRoll(Character.Head.CFrame))
		end
	else
		Camera.CameraType = Enum.CameraType.Custom
	end
end

function UpdateTargetStats(Target,Gui)
	if Target then
		local myHead = Character.Head
		local TorsoPos = Target.Character.Torso.CFrame
		local Distance = (myHead.CFrame.p - TorsoPos.p).magnitude
		local TargetSpeed = (Target.Character.Torso.Velocity).magnitude
		local TargetAlt = Target.Character.Torso.Position.Y
		Gui.LockName.Text = ("Target: %s"):format(Target.Name)
		Gui.Dist.Text = ("Distance: %s"):format(tostring(math.floor(Distance * 10)/10))
		Gui.Speed.Text = ("Speed: %s"):format(tostring(math.floor(TargetSpeed * 10)/10))
		Gui.Altitude.Text = ("Altitude: %s"):format(tostring(math.floor(TargetAlt * 10)/10))
	elseif (not Target) then
		Gui.LockName.Text = "Target: None"
		Gui.Dist.Text = "Distance: N/A"
		Gui.Speed.Text = "Speed: N/A"
		Gui.Altitude.Text = "Altitude: N/A"
	end
end

function UpdateHUD(Gui)
	Gui.Roll.Rotation = math.deg(GetRoll(Character.Head.CFrame))
	local PitchNum = math.deg(GetPitch(Character.Head.CFrame))/90
	Gui.Roll.Pitch.Position = UDim2.new(0,-200,0,-500 + (PitchNum * 450))
	local SpeedScaled = TrueAirSpeed/50
	Gui.Speed.Main.Position = UDim2.new(0,0,0.5,SpeedScaled * 75)
	Gui.Speed.Disp.Text.Text = RoundNumber(TrueAirSpeed)
	local AltScaled = RoundNumber(Engine.Position.Y)/500
	Gui.Altitude.Main.Position = UDim2.new(0,0,0.5,AltScaled * 75)
	Gui.Altitude.Disp.Text.Text = RoundNumber(Engine.Position.Y)
	local NegFactor = (Engine.Velocity.y/math.abs(Engine.Velocity.y))
	local VerticalSpeed = RoundNumber(math.abs(Engine.Velocity.y))
	Gui.ClimbRate.Text = ("VSI: %i"):format(VerticalSpeed * NegFactor)
	Gui.GearStatus.Text = (GearUp and "Gear Up" or "Gear Down")
	Gui.GearStatus.TextColor3 = (GearUp and Color3.new(0,1,0) or Color3.new(1,0,0))
	Gui.EngineStatus.Text = (EngineOn and "Engine On" or "Engine Off")
	Gui.EngineStatus.TextColor3 = (EngineOn and Color3.new(0,1,0) or Color3.new(1,0,0))
	Gui.StallWarn.Visible = ((not Taxi()) and Stall())
	Gui.PullUp.Visible = (EngineOn and (not Taxi()) and (AltRestrict.Value) and (Engine.Position.Y < (MinAltitude2 + 20)))
	Gui.TaxiStatus.Visible = (Engine and Taxi())
	Gui.Throttle.Bar.Tray.Position = UDim2.new(0,0,1,-(Throttle * 460))
	Gui.Throttle.Bar.Tray.Size = UDim2.new(1,0,0,(Throttle * 460))
	Gui.Throttle.Disp.Text = math.abs(math.floor(Throttle * 100)).."%"
	local StallLinePos = (StallSpeed2/math.floor(TrueAirSpeed + 0.5)) * (StallSpeed2/MaxSpeed2)
	local StallLinePosFix = (StallLinePos > 1 and 1 or StallLinePos < 0 and 0 or StallLinePos)
	Gui.Throttle.Bar.StallLine.Position = UDim2.new(0,0,1 - StallLinePosFix,0)
	Gui.Throttle.Bar.Tray.BackgroundColor3 = (Throttle <= StallLinePosFix and Color3.new(1,0,0) or Color3.new(0,1,0))
end

function UpdateGui(Taxiing,Stalling)
	local Gui = GuiClone.Main
	local TargetStats = GuiClone.Target
	local HUD = Player.PlayerGui.PlaneGui.HUD
	Gui.Visible = ((not HUDOnLock.Value) or (HUDOnLock.Value and (not LockedCam)))
	HUD.Visible = (LockedCam and HUDOnLock.Value)
	if LockedCam and HUDOnLock.Value then UpdateHUD(HUD) end
	if Targetable2 then UpdateTargetStats(TargetPlayer,TargetStats) end
	Gui.PullUp.Visible = (EngineOn and (not Taxiing) and (AltRestrict.Value) and (Engine.Position.Y < (MinAltitude2 + 20)))
	Gui.Taxi.Visible = (EngineOn and Taxiing)
	Gui.Stall.Visible = ((not Taxiing) and Stalling)
	Gui.Altitude.Text = "Altitude: "..RoundNumber(Engine.Position.Y)
	Gui.Speed.Text = "Speed: "..RoundNumber(TrueAirSpeed)
	Gui.Throttle.Bar.Tray.Size = UDim2.new(Throttle,0,1,0)
	Gui.Throttle.Percent.Text = math.abs(math.floor(Throttle * 100)).."%"
	local StallLinePos = (StallSpeed2/math.floor(TrueAirSpeed + 0.5)) * (StallSpeed2/MaxSpeed2)
	local StallLinePosFix = (StallLinePos > 1 and 1 or StallLinePos < 0 and 0 or StallLinePos)
	Gui.Throttle.Bar.StallLine.Position = UDim2.new(StallLinePosFix,0,0,0)
	Gui.Throttle.Bar.Tray.BackgroundColor3 = (Throttle <= StallLinePosFix and Color3.new(1,0,0) or Color3.new(0,2/3,0))
end

function CalculateSpeed()
	while Selected do
		if EngineOn then
			CurrentSpeed = (CurrentSpeed < DesiredSpeed and CurrentSpeed + 2 or CurrentSpeed - 2)
			CurrentSpeed = (CurrentSpeed < 0 and 0 or CurrentSpeed > MaxSpeed2 and MaxSpeed2 or CurrentSpeed)
		end
		wait(0.5 - (Acceleration2/2000))
	end
end

function GetLowestPoint()
	if (#LandingGear == 0) then
		LowestPoint = (Engine.Position.Y + 5 + (Engine.Size.Y/2))
		return
	end
	for i,v in pairs(LandingGear) do
		local Set0 = (Engine.Position.Y - (v.CFrame * CFrame.new((v.Size.X/2),0,0)).Y)
		local Set1 = (Engine.Position.Y - (v.CFrame * CFrame.new(-(v.Size.X/2),0,0)).Y)
		local Set2 = (Engine.Position.Y - (v.CFrame * CFrame.new(0,(v.Size.Y/2),0)).Y)
		local Set3 = (Engine.Position.Y - (v.CFrame * CFrame.new(0,-(v.Size.Y/2),0)).Y)
		local Set4 = (Engine.Position.Y - (v.CFrame * CFrame.new(0,0,(v.Size.Z/2))).Y)
		local Set5 = (Engine.Position.Y - (v.CFrame * CFrame.new(0,0,-(v.Size.Z/2))).Y)
		local Max = (math.max(Set0,Set1,Set2,Set3,Set4,Set5) + 5)
		LowestPoint = (Max > LowestPoint and Max or LowestPoint)
	end
end

function GetBankAngle(M)
	local VSX,X = M.ViewSizeX,M.X
	local Ratio = (((VSX/2) - X)/(VSX/2))
	Ratio = (Ratio < -1 and -1 or Ratio > 1 and 1 or Ratio)
	return math.rad(Ratio * MaxBank2)
end

function Taxi()
	local Ray = Ray.new(Engine.Position,Vector3.new(0,-LowestPoint,0))
	return (TrueAirSpeed <= StallSpeed2 and game.Workspace:FindPartOnRay(Ray,Plane))
end

function Stall()
	return ((AltRestrict.Value and Engine.Position.Y > MaxAltitude2) or TrueAirSpeed < StallSpeed2)
end

function FlyMain(M)
	if Selected then
		local BankAngle = GetBankAngle(M)
		local Taxi,Stall = Taxi(),Stall()
		if EngineOn then
			Engine.Thrust.velocity = (Engine.CFrame.lookVector * CurrentSpeed) + Vector3.new(0,0.15,0)
			if Taxi then
				if (CurrentSpeed < 2) then
					Thrust.maxForce = Vector3.new(0,0,0)
					Direction.maxTorque = Vector3.new(0,0,0)
				else
					Thrust.maxForce = Vector3.new(math.huge,0,math.huge)
					Direction.maxTorque = Vector3.new(0,math.huge,0)
					Direction.cframe = CFrame.new(Engine.Position,M.Hit.p)
				end
			elseif Stall then
				Thrust.maxForce = Vector3.new(0,0,0)
				Direction.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
				Direction.cframe = (M.Hit*CFrame.Angles(0,0,BankAngle))
			else
				Thrust.maxForce = Vector3.new(math.huge,math.huge,math.huge)
				Direction.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
				Direction.cframe = (M.Hit*CFrame.Angles(0,0,BankAngle))
			end
			if ((AltRestrict.Value) and (Engine.Position.Y < MinAltitude2)) then
				AutoCrash.Value = true
			end
		elseif (not EngineOn) then
			Thrust.maxForce = Vector3.new(0,0,0)
			Thrust.velocity = Vector3.new(0,0,0)
			Direction.maxTorque = Vector3.new(0,0,0)
		end
		TrueAirSpeed = Engine.Velocity.magnitude
		UpdateGui(Taxi,Stall)
		wait()
	end
end

function onKeyDown(Key)
	Key:lower()
	if (Key == FlightControls.Engine.Value) then
		local Gui = GuiClone.Main
		if (not EngineOn) then
			EngineOn = true
			DesiredSpeed = 0
			CurrentSpeed = 0
			Throttle = 0
			Gui.Engine.Visible = false
			CalculateSpeed()
		elseif EngineOn then
			EngineOn = false
			DesiredSpeed = 0
			CurrentSpeed = 0
			Throttle = 0
			Gui.Engine.Visible = true
		end
	end
	if (Key == FlightControls.Gear.Value) then
		local Gui = GuiClone.Main
		local Taxiing = Taxi()
		if (#LandingGear ~= 0) then
			if (not Taxiing) then
				ChangeGear()
				if (not GearUp) then
					GearUp = true
					Gui.Gear.Text = "Gear Up"
				elseif GearUp then
					GearUp = false
					Gui.Gear.Text = "Gear Down"
				end
			end
		end
	end
	if SUAK and Key:byte() == SpeedUp2 or (not SUAK) and (Key == SpeedUp2) then
		Accelerating = true
		IncreaseSpd()
	end
	if SDAK and Key:byte() == SlowDown2 or (not SDAK) and (Key == SlowDown2) then
		Decelerating = true
		DecreaseSpd()
	end
	if (Key == TargetControls.Modes.Value) then
		if Targetable2 then
			if EngineOn then
				if (not Targeting) then
					Targeting = true
				elseif Targeting then
					Targeting = false
					Locked = false
					AimGui.Enabled = false
					LockGui.Enabled = false
				end
			end
		end
	end
	if (Key == FlightControls.Eject.Value:lower()) then
		if EngineOn then
			local Taxiing = Taxi()
			if (not Taxiing) then
				if Ejectable.Value then
					if (not Plane.Ejected.Value) then
						Plane.Ejected.Value = true
						local Seat = MainParts.Seat
						local EjectClone = Tool.Ejector:clone()
						EjectClone.Parent = Player.PlayerGui
						EjectClone.Disabled = false
						local Fire = Instance.new("Fire")
						Fire.Parent = Engine
						Fire.Heat = 25
						Fire.Size = 30
						local Smoke = Instance.new("Smoke")
						Smoke.Parent = Engine
						Smoke.Color = Color3.new(1/3,1/3,1/3)
						Smoke.Opacity = 0.7
						Smoke.RiseVelocity = 10
						Smoke.Size = 10
						Seat.SeatWeld:remove()
					end
				end
			end
		end
	end
	if (Key == FlightControls.LockCam.Value) then
		LockedCam = (not LockedCam)
	end
	if (Key == WeaponControls.FireGuns.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Guns.Value then
				if EngineOn then
					local Taxiing = Taxi()
					if (not Taxiing) then
						FiringGun = true
						FireMachineGun(Weapons)
					end
				end
			end
		end
	end
	if (Key == WeaponControls.FireRockets.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Rockets.Value then
				local Taxiing = Taxi()
				if (not Taxiing) then
					if RocketEnabled then
						RocketEnabled = false
						FireRockets(Weapons)
						ReloadRocket(RocketTime2)
					end
				end
			end
		end
	end
	if (Key == WeaponControls.DeployFlares.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Flares.Value then
				if EngineOn then
					local Taxiing = Taxi()
					if (not Taxiing) then
						if FlareEnabled then
							FlareEnabled = false
							for i = 1,5 do
								DeployFlares(Weapons)
								wait(0.2)
							end
							ReloadFlare(FlareTime2)
						end
					end
				end
			end
		end
	end
	if (Key == WeaponControls.DropBombs.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Bombs.Value then
				if EngineOn then
					local Taxiing = Taxi()
					if (not Taxiing) then
						if BombEnabled then
							BombEnabled = false
							local BombSpawns = {}
							for i,v in pairs(Weapons:GetChildren()) do
								if v:IsA("BasePart") then
									if v.Name == "BombSpawn" then
										table.insert(BombSpawns,v)
									end
								end
							end
							local CurrentSpawn = BombSpawns[math.random(1,#BombSpawns)]
							if Locked then
								DropGuidedBomb(CurrentSpawn)
								ReloadBomb((BombTime2 * 2))
							elseif (not Locked) then
								for i = 1,5 do
									DropBomb(Weapons)
									wait(0.3)
								end
								ReloadBomb(BombTime2)
							end
						end
					end
				end
			end
		end
	end
	if (Key == WeaponControls.FireMissile.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Missiles.Value then
				if EngineOn then
					local Taxiing = Taxi()
					if (not Taxiing) then
						if MissileEnabled then
							MissileEnabled = false
							local MissileSpawns = {}
							for i,v in pairs(Weapons:GetChildren()) do
								if v:IsA("BasePart") then
									if v.Name == "MissileSpawn" then
										table.insert(MissileSpawns,v)
									end
								end
							end
							local CurrentSpawn = MissileSpawns[math.random(1,#MissileSpawns)]
							if Locked then
								FireGuidedMissile(CurrentSpawn)
								ReloadMissile((MissileTime2 * 2))
							elseif (not Locked) then
								FireMissile(CurrentSpawn)
								ReloadMissile(MissileTime2)
							end
						end
					end
				end
			end
		end
	end
	if (Key == TargetControls.UnTarget.Value) then
		if Targetable2 then
			if Locked then
				Locked = false
			end
		end
	end
end

function onKeyUp(Key)
	Key:lower()
	if SUAK and Key:byte() == SpeedUp2 or (not SUAK) and (Key == SpeedUp2) then
		Accelerating = false
	end
	if SDAK and Key:byte() == SlowDown2 or (not SDAK) and (Key == SlowDown2) then
		Decelerating = false
	end
	if (Key == WeaponControls.FireGuns.Value) then
		FiringGun = false
	end
end

function onSelected(mouse)
	Selected = true
	mouse2 = mouse
	FixVars()
	GetGear(Gear)
	GetLowestPoint()
	ToolSelect.Value = true
	GuiClone = GUI:clone()
	GuiClone.Parent = Player.PlayerGui
	SetUpGui()
	Camera.CameraType = CameraType2
	if Targetable2 then
		AimGui = Instance.new("BillboardGui",Player.PlayerGui)
		AimGui.AlwaysOnTop = true
		AimGui.Enabled = false
		AimGui.Size = UDim2.new(0,50,0,50)
		local Label = Instance.new("ImageLabel",AimGui)
		Label.BackgroundTransparency = 1
		Label.Image = "http://www.roblox.com/asset/?id=107388694"
		Label.Size = UDim2.new(1,0,1,0)
		LockGui = Instance.new("BillboardGui",Player.PlayerGui)
		LockGui.AlwaysOnTop = true
		LockGui.Enabled = false
		LockGui.Size = UDim2.new(0,50,0,50)
		local Label = Instance.new("ImageLabel",LockGui)
		Label.BackgroundTransparency = 1
		Label.Image = "http://www.roblox.com/asset/?id=107388656"
		Label.Size = UDim2.new(1,0,1,0)
	end
	mouse.Icon = NormalCursor
	FTab[1] = mouse.Move:connect(function() onMouseMoved(mouse) end)
	FTab[2] = mouse.Idle:connect(function() onMouseMoved(mouse) end)
	FTab[3] = mouse.Button1Down:connect(function() onButton1Down(mouse) end)
	FTab[4] = mouse.KeyDown:connect(onKeyDown)
	FTab[5] = mouse.KeyUp:connect(onKeyUp)
	FTab[6] = RunService.RenderStepped:connect(UpdateCamera)
	FTab[7] = RunService.Stepped:connect(function() FlyMain(mouse) end)
end

function onDeselected(mouse)
	Selected = false
	LockedCam = false
	for i,v in pairs(FTab) do
		if v then
			v:disconnect()
		end
	end
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CameraSubject = Character.Humanoid
	if Targetable2 then
		AimGui:remove()
		LockGui:remove()
	end
	if (not Taxi()) and EngineOn then
		if (not Deselect0.Value) and (not Plane.Ejected.Value) then
			onDeselectFlying()
		end
	end
	CurrentSpeed = 0
	DesiredSpeed = 0
	TrueAirSpeed = 0
	EngineOn = false
	Updating = false
	Locked = false
	Targeting = false
	TargetPlayer = nil
	ToolSelect.Value = false
	GuiAVisible = true
	GuiBVisible = true
	GuiClone:remove()
	Engine.Thrust.velocity = Vector3.new(0,0,0)
	Engine.Thrust.maxForce = Vector3.new(0,0,0)
	Engine.Direction.maxTorque = Vector3.new(0,0,0)
end

function onDeselectFlying()
	if (not Deselect0.Value) then
		local Explosion = Instance.new("Explosion")
		Explosion.Parent = game.Workspace
		Explosion.Position = Engine.Position
		Explosion.BlastRadius = Plane:GetModelSize().magnitude
		Explosion.BlastPressure = 100000
		Character.Humanoid.Health = 0
		Engine.Thrust:remove()
		Engine.Direction:remove()
		script.Parent.PlaneGui.Enabled = false
		delay(5,function()
			Plane:Destroy()
		end)
	end
end

function onDeselectForced()
	if Deselect0.Value then
		onDeselected()
		mouse2.Icon = "rbxasset://textures\\ArrowCursor.png"
	end
end

script.Parent.Selected:connect(onSelected)
script.Parent.Deselected:connect(onDeselected)
Deselect0.Changed:connect(onDeselectForced)

I got a free model and edited it.
All of this is in a local script.
What should I put in a script and what should I put in a local? I can see when my testers move.
Thanks for reading.
Please help!!!

1 Like

You can’t damage another player with a weapon that’s scripted by a localscript

1 Like

Right now what is happening is that the players can see each other’s planes, but they can’t see the bullets, missiles, and bombs. If Player 1 destroys Player 2’s plane, only for player 1 the plane is destroyed. Player 2 does not see anything wrong and on their screen, their plane is perfectly fine.

This is because it’s a LocalScript and I can tell it’s a hopperbin since it uses Selected and Deselected.

Edit - I’ll notify you if I get it working.

1 Like

So then should I copy paste the entire script then post into a regular script?

That won’t just fix it, you must change things such as selected to equipped, deselected to unequipped, get keydown from remote functions, etc. One again, I’ll notify you if I get it working.

1 Like

tsym, get it working and i will send you 10 robux. (if its allowed.)

I don’t have the planes so I cannot garuntee this will work.

Make a tool and make the RequiresHandle property false. Make 5 RemoteEvents and parent them into the tool. Name one RemoteEvent “RenderSteppedEvent”, another “SteppedEvent”, another “keyUpEvent”, another “moveEvent”, and the last “keyDownEvent”. Make a vector3value and parent it into the tool and name it “mouse”, now for the scripts.

-- Server script

repeat wait() until game.Players:GetPlayerFromCharacter(script.Parent.Parent) ~= nil or game.Players:FindFirstChild(script.Parent.Parent.Parent.Name) ~= nil
local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) -- game.Players.LocalPlayer
if Player == nil then Player = game.Players:FindFirstChild(script.Parent.Parent.Parent.Name) end
local Character = Player.Character
local Plane = Character:WaitForChild("Plane")
local AutoCrash = Plane.AutoCrash
local Weapons = Plane.Weapons
local MainParts = Plane.MainParts
local Gear = MainParts.Gear
local Engine = MainParts.Engine
local Thrust = Engine.Thrust
local Direction = Engine.Direction
local Customize = Plane.Customize
local Tool = script.Parent
local GUI = Tool.PlaneGui
local ToolSelect = Tool.ToolSelect
local Deselect0 = Tool.Deselect0
local FireMain = Tool.FireMain
local Camera = game.Workspace.CurrentCamera
local RunService = game:GetService("RunService")
local Acceleration = Customize.Acceleration
local MaxSpeed = Customize.MaxSpeed
local StallSpeed = Customize.StallSpeed
local TurnSpeed = Customize.TurnSpeed
local ThrottleInc = Customize.ThrottleInc
local MaxBank = Customize.MaxBank
local CameraType = Customize.CameraType
local CamLock = Customize.CamLock
local HUDOnLock = Customize.HUDOnLock
local Ejectable = Customize.Ejectable
local PlaneName = Customize.PlaneName
local Targetable = Customize.Targetable
local FlightControls = Customize.FlightControls
local WeaponControls = Customize.WeaponControls
local TargetControls = Customize.TargetControls
local WeaponsValue = Customize.Weapons
local ReloadTimes = Customize.ReloadTimes
local AltRestrict = Customize.AltitudeRestrict
local MaxAltitude = AltRestrict.MaxAltitude
local MinAltitude = AltRestrict.MinAltitude
local GuiAVisible = true
local GuiBVisible = true
local BombM = FireMain.BombM
local MissileM = FireMain.MissileM
local RocketEnabled = true
local FlareEnabled = true
local BombEnabled = true
local MissileEnabled = true
local SUAK = false
local SDAK = false
local EngineOn = false
local Selected = false
local LockedCam = false
local LowestPoint = 0
local DesiredSpeed = 0
local CurrentSpeed = 0
local TrueAirSpeed = 0
local Throttle = 0
local FTab = {nil,nil,nil,nil,nil,nil,nil}
local LockGui = nil
local AimGui = nil
local TargetPlayer = nil
local Locked = false
local Targeting = false
local AimingCursor = "http://www.roblox.com/asset/?id=107455536"
local LockedCursor = "http://www.roblox.com/asset/?id=107455986"
local TargetCursor = "http://www.roblox.com/asset/?id=107455960"
local NormalCursor = "http://www.roblox.com/asset/?id=116176885"
local LandingGear = {}
local GearUp = false

function FixVars()
	Acceleration2 = (Acceleration.Value < 0 and 0 or Acceleration.Value > 1000 and 1000 or Acceleration.Value)
	MaxBank2 = (MaxBank.Value < -90 and -90 or MaxBank.Value > 90 and 90 or MaxBank.Value)
	MaxSpeed2 = (MaxSpeed.Value < 0 and 0 or MaxSpeed.Value < StallSpeed.Value and StallSpeed.Value or MaxSpeed.Value)
	StallSpeed2 = (StallSpeed.Value < 0 and 0 or StallSpeed.Value > MaxSpeed.Value and MaxSpeed.Value or StallSpeed.Value)
	TurnSpeed2 = (TurnSpeed.Value < 0 and 0 or TurnSpeed.Value)
	ThrottleInc2 = (ThrottleInc.Value < 0 and 0 or ThrottleInc.Value)
	MaxAltitude2 = (MaxAltitude.Value < MinAltitude.Value and MinAltitude.Value or MaxAltitude.Value)
	MinAltitude2 = (MinAltitude.Value > MaxAltitude.Value and MaxAltitude.Value or MinAltitude.Value)
	MissileTime2 = (ReloadTimes.Missiles.Value < 0 and 0 or ReloadTimes.Missiles.Value)
	RocketTime2 = (ReloadTimes.Rockets.Value < 0 and 0 or ReloadTimes.Rockets.Value)
	GunTime2 = (ReloadTimes.Guns.Value < 0 and 0 or ReloadTimes.Guns.Value)
	FlareTime2 = (ReloadTimes.Flares.Value < 0 and 0 or ReloadTimes.Flares.Value)
	BombTime2 = (ReloadTimes.Bombs.Value < 0 and 0 or ReloadTimes.Bombs.Value)
	CameraType2 = (pcall(function() Camera.CameraType = CameraType.Value end) and CameraType.Value or "Custom")
	PlaneName2 = (PlaneName.Value == "" and "Plane" or PlaneName.Value)
	if WeaponsValue.Value then
		if WeaponsValue.Missiles.Value or WeaponsValue.Bombs.Value then
			Targetable2 = true
		elseif (not (WeaponsValue.Missiles.Value and WeaponsValue.Bombs.Value)) then
			Targetable2 = false
		end
	elseif (not WeaponsValue.Value) then
		Targetable2 = false
	end
	if FlightControls.SpeedUp.Value == "ArrowKeyUp" then
		SpeedUp2 = 17
		SUAK = true
	elseif FlightControls.SpeedUp.Value == "ArrowKeyDown" then
		SpeedUp2 = 18
		SUAK = true
	else
		SpeedUp2 = FlightControls.SpeedUp.Value
		SUAK = false
	end
	if FlightControls.SlowDown.Value == "ArrowKeyUp" then
		SlowDown2 = 17
		SDAK = true
	elseif FlightControls.SlowDown.Value == "ArrowKeyDown" then
		SlowDown2 = 18
		SDAK = true
	else
		SlowDown2 = FlightControls.SlowDown.Value
		SDAK = false
	end
	Engine.Direction.P = TurnSpeed2
end

function FireMachineGun(GunParent)
	while FiringGun do
		for _,v in pairs(GunParent:GetChildren()) do
			if v:IsA("BasePart") then
				if v.Name == "MachineGun" then
					local Part = Instance.new("Part")
					Part.BrickColor = BrickColor.new("Really red")
					Part.Name = "Bullet"
					Part.CanCollide = false
					Part.FormFactor = "Symmetric"
					Part.Size = Vector3.new(5,5,3)
					Part.BottomSurface = "Smooth"
					Part.TopSurface = "Smooth"
					local Mesh = Instance.new("BlockMesh")
					Mesh.Parent = Part
					Mesh.Scale = Vector3.new(1/25,1/25,1)
					local BV = Instance.new("BodyVelocity")
					BV.Parent = Part
					BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
					local PlaneTag = Instance.new("ObjectValue")
					PlaneTag.Parent = Part
					PlaneTag.Name = "PlaneTag"
					PlaneTag.Value = Plane
					Part.Touched:connect(function(Object)
						if (not Object:IsDescendantOf(Character)) then
							local HitHumanoid = Object.Parent:findFirstChild("Humanoid")
							if HitHumanoid then
								HitHumanoid:TakeDamage(100)
								local CreatorTag = Instance.new("ObjectValue")
								CreatorTag.Name = "creator"
								CreatorTag.Value = Player
								CreatorTag.Parent = HitHumanoid
							elseif (not HitHumanoid) and Object.Name ~= "SpawnLocation" and Object.Name ~= "Main" and Object.Name ~= "Platiform" then
								print("Steel Inquisitor is curious about this issue.")
								Object:Destroy()
							end
						end
					end)
					Part.Parent = game.Workspace
					Part.CFrame = v.CFrame + v.CFrame.lookVector * 10
					BV.velocity = (v.Velocity) + (Part.CFrame.lookVector * 2000) + (Vector3.new(0,0.15,0))
					delay(3,function() Part:Destroy() end)
				end
			end
		end
		wait(GunTime2)
	end
end

function FireRockets(GunParent)
	for _,v in pairs(GunParent:GetChildren()) do
		if v:IsA("BasePart") then
			if v.Name == "RocketSpawn" then
				local Exploded = false
				local Part1 = Instance.new("Part")
				Part1.BrickColor = BrickColor.new("White")
				Part1.Name = "Missile"
				Part1.CanCollide = false
				Part1.FormFactor = "Symmetric"
				Part1.Size = Vector3.new(1,1,5)
				Part1.BottomSurface = "Smooth"
				Part1.TopSurface = "Smooth"
				local Mesh = Instance.new("SpecialMesh")
				Mesh.Parent = Part1
				Mesh.MeshId = "http://www.roblox.com/asset/?id=2251534"
				Mesh.MeshType = "FileMesh"
				Mesh.Scale = Vector3.new(0.5,0.5,0.5)
				local Part2 = Instance.new("Part")
				Part2.Parent = Part1
				Part2.Transparency = 1
				Part2.Name = "Visual"
				Part2.CanCollide = false
				Part2.FormFactor = "Symmetric"
				Part2.Size = Vector3.new(1,1,1)
				Part2.BottomSurface = "Smooth"
				Part2.TopSurface = "Smooth"
				local Weld = Instance.new("Weld")
				Weld.Parent = Part1
				Weld.Part0 = Part1
				Weld.Part1 = Part2
				Weld.C0 = CFrame.new(0,0,4) * CFrame.Angles(math.rad(90),0,0)
				local BV = Instance.new("BodyVelocity")
				BV.Parent = Part1
				BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
				local BG = Instance.new("BodyGyro")
				BG.Parent = Part
				BG.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
				BG.cframe = v.CFrame
				local Fire = Instance.new("Fire")
				Fire.Parent = Part2
				Fire.Heat = 25
				Fire.Size = 10
				local Smoke = Instance.new("Smoke")
				Smoke.Parent = Part2
				Smoke.Color = Color3.new(200/255,200/255,200/255)
				Smoke.Opacity = 0.7
				Smoke.RiseVelocity = 25
				Smoke.Size = 10
				local PlaneTag = Instance.new("ObjectValue")
				PlaneTag.Parent = Part
				PlaneTag.Name = "PlaneTag"
				PlaneTag.Value = Plane
				Part1.Touched:connect(function(Object)
					if (not Exploded) then
						if (not Object:IsDescendantOf(Character)) then
							if Object.Name ~= "Missile" then
								Exploded = true
								local Explosion = Instance.new("Explosion",game.Workspace)
								Explosion.Position = Part1.Position
								Explosion.BlastPressure = 5000
								Explosion.BlastRadius = 25
								ScanPlayers(Part1.Position,25)
								Explosion.Parent = game.Workspace
								Part1:Destroy()
							end
						end
					end
				end)
				Part1.Parent = game.Workspace
				Part1.CFrame = v.CFrame + v.CFrame.lookVector * 10
				BV.velocity = Part1.CFrame.lookVector * 1250 + Vector3.new(0,0.15,0)
				delay(5,function() Part1:Destroy() end)
			end
		end
	end
end

function DeployFlares(GunParent)
	for _,v in pairs(GunParent:GetChildren()) do
		if v:IsA("BasePart") then
			if v.Name == "FlareSpawn" then
				local RandomFactor = 40
				local RandomX = math.rad(math.random(-RandomFactor,RandomFactor))
				local RandomY = math.rad(math.random(-RandomFactor,RandomFactor))
				local Part = Instance.new("Part")
				Part.Transparency = 1
				Part.Name = "Flare"
				Part.CanCollide = false
				Part.FormFactor = "Symmetric"
				Part.Size = Vector3.new(1,1,1)
				Part.BottomSurface = "Smooth"
				Part.TopSurface = "Smooth"
				local BG = Instance.new("BillboardGui")
				BG.Parent = Part
				BG.Size = UDim2.new(10,0,10,0)
				local IL = Instance.new("ImageLabel")
				IL.Parent = BG
				IL.BackgroundTransparency = 1
				IL.Image = "http://www.roblox.com/asset/?id=43708803"
				IL.Size = UDim2.new(1,0,1,0)
				local Smoke = Instance.new("Smoke")
				Smoke.Parent = Part
				Smoke.Opacity = 0.5
				Smoke.RiseVelocity = 25
				Smoke.Size = 5
				local PL = Instance.new("PointLight")
				PL.Parent = Part
				PL.Brightness = 10
				PL.Color = Color3.new(1,1,0)
				PL.Range = 20
				Part.Parent = game.Workspace
				Part.CFrame = (v.CFrame + v.CFrame.lookVector * 5) * CFrame.Angles(RandomX,RandomY,0)
				Part.Velocity = Part.CFrame.lookVector * 150
				delay(5,function() Part:Destroy() end)
			end
		end
	end
end

function DropBomb(GunParent)
	if (not Locked) then
		for _,v in pairs(GunParent:GetChildren()) do
			if v:IsA("BasePart") then
				if v.Name == "BombSpawn" then
					local Exploded = false
					local Part = Instance.new("Part")
					Part.Name = "Bomb"
					Part.CanCollide = false
					Part.FormFactor = "Symmetric"
					Part.Size = Vector3.new(2,2,9)
					Part.BottomSurface = "Smooth"
					Part.TopSurface = "Smooth"
					local Mesh = Instance.new("SpecialMesh")
					Mesh.Parent = Part
					Mesh.MeshId = "http://www.roblox.com/asset/?id=88782666"
					Mesh.MeshType = "FileMesh"
					Mesh.Scale = Vector3.new(4,4,4)
					Mesh.TextureId = "http://www.roblox.com/asset/?id=88782631"
					local BG = Instance.new("BodyGyro")
					BG.Parent = Part
					BG.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
					BG.cframe = v.CFrame * CFrame.Angles(math.rad(90),0,0)
					local PlaneTag = Instance.new("ObjectValue")
					PlaneTag.Parent = Part
					PlaneTag.Name = "PlaneTag"
					PlaneTag.Value = Plane
					Part.Touched:connect(function(Object)
						if (not Exploded) then
							if (not Object:IsDescendantOf(Character)) and Object.Name ~= "Bomb" then
								Exploded = true
								local Explosion = Instance.new("Explosion")
								Explosion.Position = Part.Position
								Explosion.BlastPressure = 500000
								Explosion.BlastRadius = 25
								ScanPlayers(Part.Position,25)
								Explosion.Parent = game.Workspace
								Part:Destroy()
							end
						end
					end)
					Part.Parent = game.Workspace
					Part.CFrame = (v.CFrame * CFrame.Angles(math.rad(90),0,0)) + v.CFrame.lookVector * 3
					Part.Velocity = (Part.CFrame.lookVector * (TrueAirSpeed * 0.75))
					delay(7,function() Part:Destroy() end)
				end
			end
		end
	end
end

function DropGuidedBomb(Gun)
	if Locked then
		local Exploded = false
		local Part = Instance.new("Part")
		Part.Name = "Bomb"
		Part.CanCollide = false
		Part.FormFactor = "Symmetric"
		Part.Size = Vector3.new(2,2,9)
		Part.BottomSurface = "Smooth"
		Part.TopSurface = "Smooth"
		local Mesh = Instance.new("SpecialMesh")
		Mesh.Parent = Part
		Mesh.MeshId = "http://www.roblox.com/asset/?id=88782666"
		Mesh.MeshType = "FileMesh"
		Mesh.Scale = Vector3.new(4,4,4)
		Mesh.TextureId = "http://www.roblox.com/asset/?id=88782631"
		local OV = Instance.new("ObjectValue")
		OV.Parent = Part
		OV.Name = "Tracker"
		OV.Value = TargetPlayer.Character.Torso
		local NV = Instance.new("NumberValue")
		NV.Parent = Part
		NV.Name = "PlaneSpd"
		NV.Value = TrueAirSpeed * 0.8
		local BG = Instance.new("BodyGyro")
		BG.Parent = Part
		BG.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
		BG.P = 2000
		local BV = Instance.new("BodyVelocity")
		BV.Parent = Part
		BV.maxForce = Vector3.new(math.huge,6000,math.huge)
		BV.velocity = Vector3.new(0,0,0)
		local Script = BombM:clone()
		Script.Parent = Part
		local PlaneTag = Instance.new("ObjectValue")
		PlaneTag.Parent = Part
		PlaneTag.Name = "PlaneTag"
		PlaneTag.Value = Plane
		Part.Touched:connect(function(Object)
			if (not Exploded) then
				if (not Object:IsDescendantOf(Character)) and Object.Name ~= "Bomb" then
					Exploded = true
					local Explosion = Instance.new("Explosion")
					Explosion.Position = Part.Position
					Explosion.BlastPressure = 500000
					Explosion.BlastRadius = 25
					ScanPlayers(Part.Position,25)
					Explosion.Parent = game.Workspace
					Part:Destroy()
				end
			end
		end)
		Part.Parent = game.Workspace
		Part.CFrame = (Gun.CFrame * CFrame.Angles(math.rad(90),0,0)) + Gun.CFrame.lookVector * 10
		Script.Disabled = false
	end
end

function FireMissile(Gun)
	if (not Locked) then
		local Exploded = false
		local Part1 = Instance.new("Part")
		Part1.Name = "Missile"
		Part1.CanCollide = false
		Part1.FormFactor = "Symmetric"
		Part1.Size = Vector3.new(1,1,13)
		Part1.BottomSurface = "Smooth"
		Part1.TopSurface = "Smooth"
		local Mesh = Instance.new("SpecialMesh")
		Mesh.Parent = Part1
		Mesh.MeshId = "http://www.roblox.com/asset/?id=2251534"
		Mesh.MeshType = "FileMesh"
		Mesh.TextureId = "http://www.roblox.com/asset/?id=2564491"
		local Part2 = Instance.new("Part")
		Part2.Parent = Part1
		Part2.Name = "Visual"
		Part2.Transparency = 1
		Part2.CanCollide = false
		Part2.FormFactor = "Symmetric"
		Part2.Size = Vector3.new(1,1,1)
		Part2.BottomSurface = "Smooth"
		Part2.TopSurface = "Smooth"
		local Weld = Instance.new("Weld")
		Weld.Parent = Part1
		Weld.Part0 = Part1
		Weld.Part1 = Part2
		Weld.C0 = CFrame.new(0,0,5)*CFrame.Angles(math.rad(90),0,0)
		local BV = Instance.new("BodyVelocity")
		BV.Parent = Part1
		BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
		local BG = Instance.new("BodyGyro")
		BG.Parent = Part
		BG.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
		BG.cframe = Gun.CFrame * CFrame.Angles(math.rad(90),0,0)
		local Fire = Instance.new("Fire")
		Fire.Parent = Part2
		Fire.Enabled = false
		Fire.Heat = 25
		Fire.Size = 30
		local Smoke = Instance.new("Smoke")
		Smoke.Parent = Part2
		Smoke.Color = Color3.new(40/51,40/51,40/51)
		Smoke.Enabled = false
		Smoke.Opacity = 1
		Smoke.RiseVelocity = 25
		Smoke.Size = 25
		local PlaneTag = Instance.new("ObjectValue")
		PlaneTag.Parent = Part
		PlaneTag.Name = "PlaneTag"
		PlaneTag.Value = Plane
		Part1.Touched:connect(function(Object)
			if (not Exploded) then
				if (not Object:IsDescendantOf(Character)) and Object.Name ~= "Missile" then
					Exploded = true
					local Explosion = Instance.new("Explosion")
					Explosion.Position = Part1.Position
					Explosion.BlastPressure = 50000
					Explosion.BlastRadius = 25
					ScanPlayers(Part1.Position,25)
					Explosion.Parent = game.Workspace
					Part1:Destroy()
				end
			end
		end)
		Part1.Parent = game.Workspace
		Part1.CFrame = (Gun.CFrame * CFrame.Angles(math.rad(90),0,0)) + Gun.CFrame.lookVector * 15
		BV.velocity = Part1.CFrame.lookVector * Engine.Velocity.magnitude
		delay(0.3,function()
			BV.velocity = (Part1.CFrame.lookVector * 1500) + Vector3.new(0,0.15,0)
			Fire.Enabled = true
			Smoke.Enabled = true
		end)
		delay(5,function() Part1:Destroy() end)
	end
end

function FireGuidedMissile(Gun)
	if Targetable2 then
		if Locked then
			local Exploded = false
			local Part1 = Instance.new("Part")
			Part1.Name = "Missile"
			Part1.CanCollide = false
			Part1.FormFactor = "Symmetric"
			Part1.Size = Vector3.new(1,1,13)
			Part1.BottomSurface = "Smooth"
			Part1.TopSurface = "Smooth"
			local Mesh = Instance.new("SpecialMesh")
			Mesh.Parent = Part1
			Mesh.MeshId = "http://www.roblox.com/asset/?id=2251534"
			Mesh.MeshType = "FileMesh"
			Mesh.TextureId = "http://www.roblox.com/asset/?id=2564491"
			local Part2 = Instance.new("Part")
			Part2.Parent = Part1
			Part2.Transparency = 1
			Part2.Name = "Visual"
			Part2.CanCollide = false
			Part2.FormFactor = "Symmetric"
			Part2.Size = Vector3.new(1,1,1)
			Part2.BottomSurface = "Smooth"
			Part2.TopSurface = "Smooth"
			local Weld = Instance.new("Weld")
			Weld.Parent = Part1
			Weld.Part0 = Part1
			Weld.Part1 = Part2
			Weld.C0 = CFrame.new(0,0,5)*CFrame.Angles(math.rad(90),0,0)
			local OV = Instance.new("ObjectValue")
			OV.Parent = Part1
			OV.Name = "Tracker"
			OV.Value = TargetPlayer.Character.Torso
			local BV = Instance.new("BodyVelocity")
			BV.Parent = Part1
			BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
			local Script = MissileM:clone()
			Script.Parent = Part1
			local Fire = Instance.new("Fire")
			Fire.Parent = Part2
			Fire.Enabled = false
			Fire.Heat = 25
			Fire.Size = 30
			local Smoke = Instance.new("Smoke")
			Smoke.Parent = Part2
			Smoke.Color = Color3.new(40/51,40/51,40/51)
			Smoke.Enabled = false
			Smoke.Opacity = 1
			Smoke.RiseVelocity = 25
			Smoke.Size = 25
			local PlaneTag = Instance.new("ObjectValue")
			PlaneTag.Parent = Part
			PlaneTag.Name = "PlaneTag"
			PlaneTag.Value = Plane
			Part1.Touched:connect(function(Object)
				if (not Exploded) then
					if (not Object:IsDescendantOf(Character)) and Object.Name ~= "Missile" then
						Exploded = true
						local Explosion = Instance.new("Explosion")
						Explosion.Position = Part1.Position
						Explosion.BlastPressure = 50000
						Explosion.BlastRadius = 25
						ScanPlayers(Part1.Position,25)
						Explosion.Parent = game.Workspace
						Part1:Destroy()
					end
				end
			end)
			Part1.Parent = game.Workspace
			Part1.CFrame = (Gun.CFrame * CFrame.Angles(math.rad(90),0,0)) + Gun.CFrame.lookVector * 15
			delay(0.3,function()
				Script.Disabled = false
				Fire.Enabled = true
				Smoke.Enabled = true
			end)
			delay(10,function() Part1:Destroy() end)
		end
	end
end

function ScanPlayers(Pos,Radius)
	coroutine.resume(coroutine.create(function()
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.Character and v.Character:findFirstChild("Torso") then
				local PTorso = v.Character.Torso
				if ((PTorso.Position - Pos).magnitude + 2) <= Radius then
					local HitHumanoid = v.Character:findFirstChild("Humanoid")
					if HitHumanoid then
						local CreatorTag = Instance.new("ObjectValue")
						CreatorTag.Name = "creator"
						CreatorTag.Value = Player
						CreatorTag.Parent = HitHumanoid
						game:GetService("Debris"):AddItem(CreatorTag,0.1)
					end
				end
			end
		end
	end))
end

function ReloadRocket(Time)
	if (not RocketEnabled) then
		wait(Time)
		RocketEnabled = true
	end
end

function ReloadFlare(Time)
	if (not FlareEnabled) then
		wait(Time)
		FlareEnabled = true
	end
end

function ReloadBomb(Time)
	if (not BombEnabled) then
		wait(Time)
		BombEnabled = true
	end
end

function ReloadMissile(Time)
	if (not MissileEnabled) then
		wait(Time)
		MissileEnabled = true
	end
end

script.Parent.moveEvent.OnServerEvent:Connect(function(player,mouse)
	script.Parent.mouse.Value = mouse
	if Targetable2 then
		local Gui = GuiClone.Main
		if Targeting then
			mouse.Icon = AimingCursor
			Gui.Mode.Text = "Targeting Mode"
			local FoundPlayer = false
			for i,v in pairs(game.Players:GetPlayers()) do
				if v.Character then
					if v.Character:findFirstChild("Torso") then
						if v ~= Player then
							if ((v.TeamColor ~= Player.TeamColor) or v.Neutral) then
								local myHead = Character.Head
								local TorsoPos = v.Character.Torso.CFrame
								local Distance = (myHead.CFrame.p - TorsoPos.p).magnitude
								local MouseDirection = (mouse - myHead.CFrame.p).unit
								local Offset = (((MouseDirection * Distance) + myHead.CFrame.p) - TorsoPos.p).magnitude
								if (not Locked) then
									if (Offset/Distance) < 0.1 then
										FoundPlayer = true
										if TargetPlayer ~= v then
											TargetPlayer = v
											mouse.Icon = TargetCursor
											AimGui.Enabled = true
											LockGui.Enabled = false
											AimGui.Adornee = TargetPlayer.Character.Torso
											LockGui.Adornee = nil
										end
									end
									if (not FoundPlayer) and TargetPlayer then
										TargetPlayer = nil
										mouse.Icon = AimingCursor
										AimGui.Enabled = false
										LockGui.Enabled = false
										AimGui.Adornee = nil
										LockGui.Adornee = nil
									end
								elseif Locked then
									mouse.Icon = LockedCursor
									AimGui.Enabled = false
									LockGui.Enabled = true
									AimGui.Adornee = nil
									LockGui.Adornee = TargetPlayer.Character.Torso
								end
							end
						end
					end
				end
			end
		elseif (not Targeting) then
			mouse.Icon = NormalCursor
			Gui.Mode.Text = "Flying Mode"
		end
	end
end)

script.Parent.Activated:Connect(function()
	Locked = ((not Locked) and TargetPlayer and Targeting and EngineOn and Targeting2)
end)

function IncreaseSpd()
	if EngineOn then
		if Selected then
			while Accelerating do
				Throttle = (Throttle < 1 and Throttle + 0.01 or 1)
				DesiredSpeed = MaxSpeed2 * Throttle
				wait(ThrottleInc2)
			end
		end
	end
end

function DecreaseSpd()
	if EngineOn then
		if Selected then
			while Decelerating do
				Throttle = (Throttle > 0 and Throttle - 0.01 or 0)
				DesiredSpeed = MaxSpeed2 * Throttle
				wait(ThrottleInc2)
			end
		end
	end
end

function RoundNumber(Num)
	return ((Num - math.floor(Num)) >= 0.5 and math.ceil(Num) or math.floor(Num))
end

function GetGear(Parent)
	for i,v in pairs(Parent:GetChildren()) do
		if (v:IsA("BasePart")) then
			if (not v:findFirstChild("GearProp")) then
				local GearProp = Instance.new("StringValue")
				GearProp.Name = "GearProp"
				GearProp.Value = v.Transparency..","..tostring(v.CanCollide)
				GearProp.Parent = v
			end
			table.insert(LandingGear,v)
		end
		GetGear(v)
	end
end

function ChangeGear()
	for i,v in pairs(LandingGear) do
		local GearProp = v.GearProp
		local Comma = GearProp.Value:find(",",1,true)
		local TransVal = tonumber(GearProp.Value:sub(1,Comma - 1))
		local CollideVal = GearProp.Value:sub(Comma + 1)
		v.Transparency = (TransVal ~= 1 and (GearUp and TransVal or 1))
		v.CanCollide = (CollideVal and (GearUp and CollideVal or false))
	end
end

function SetUpGui()
	local Gui = GuiClone.Main
	Gui.Title.Text = PlaneName2
	local TargetStats = Gui.Parent.Target
	local HUD = Gui.Parent.HUD
	local ControlsA,ControlsB = Gui.ControlsA,Gui.ControlsB
	local FrameA,FrameB = Gui.FrameA,Gui.FrameB
	local C1A,C1B = FrameA.C1.Key,FrameB.C1.Key
	local C2A,C2B = FrameA.C2.Key,FrameB.C2.Key
	local C3A,C3B = FrameA.C3.Key,FrameB.C3.Key
	local C4A,C4B = FrameA.C4.Key,FrameB.C4.Key
	local C5A,C5B = FrameA.C5.Key,FrameB.C5.Key
	local C6,C7 = FrameA.C6.Key,FrameA.C7.Key
	local GearText = Gui.Gear
	for i,v in pairs(LandingGear) do
		if v.Transparency == 1 then
			GearUp = true
		else
			GearUp = false
			break
		end
	end
	local MaxSpeedScaled = math.ceil(MaxSpeed2/50)
	for i = 1,(MaxSpeedScaled + 10) do
		local SpeedGui = HUD.Speed.Main
		local Speed0 = SpeedGui["Speed-0"]
		local SpeedClone = Speed0:clone()
		SpeedClone.Position = UDim2.new(0,0,1,-(80 + (75 * i)))
		SpeedClone.Name = ("Speed-%i"):format(50 * i)
		SpeedClone.Text.Text = tostring(50 * i)
		SpeedClone.Parent = SpeedGui
	end
	local MaxAltScaled = math.ceil(MaxAltitude2/500)
	for i = 1,(MaxAltScaled + 10) do
		local AltGui = HUD.Altitude.Main
		local Altitude0 = AltGui["Altitude-0"]
		local AltClone = Altitude0:clone()
		AltClone.Position = UDim2.new(0,0,1,-(80 + (75 * i)))
		AltClone.Name = ("Altitude-%s"):format(tostring(0.5 * i))
		AltClone.Text.Text = tostring(0.5 * i)
		AltClone.Parent = AltGui
	end
	GearText.Text = (GearUp and "Gear Up" or "Gear Down")
	C1A.Text = "Key: "..FlightControls.Engine.Value:upper()
	if FlightControls.SpeedUp.Value == "ArrowKeyUp" then
		C2A.Text = "Key: ArrowKeyUp"
	elseif FlightControls.SpeedUp.Value == "ArrowKeyDown" then
		C2A.Text = "Key: ArrowKeyDown"
	else
		C2A.Text = "Key: "..FlightControls.SpeedUp.Value:upper()
	end
	if FlightControls.SlowDown.Value == "ArrowKeyUp" then
		C3A.Text = "Key: ArrowKeyUp"
	elseif FlightControls.SlowDown.Value == "ArrowKeyDown" then
		C3A.Text = "Key: ArrowKeyDown"
	else
		C3A.Text = "Key: "..FlightControls.SlowDown.Value:upper()
	end
	C4A.Text = "Key: "..FlightControls.Gear.Value:upper()
	if Targetable2 then
		C5A.Text = "Key: "..TargetControls.Modes.Value:upper()
	else
		C5A.Parent.Visible = false
	end
	if Ejectable.Value then
		C6.Text = "Key: "..FlightControls.Eject.Value:upper()
	else
		C6.Parent.Visible = false
	end
	if CamLock.Value then
		C7.Text = "Key: "..FlightControls.LockCam.Value:upper()
	else
		C7.Parent.Visible = false
	end
	if (not WeaponsValue.Value) then
		C1B.Parent.Visible = false
		C2B.Parent.Visible = false
		C3B.Parent.Visible = false
		C4B.Parent.Visible = false
		C5B.Parent.Visible = false
		FrameB.Title.Text = "No Weapons"
	elseif WeaponsValue.Value then
		if WeaponsValue.Missiles.Value then
			C1B.Text = "Key: "..WeaponControls.FireMissile.Value:upper()
		elseif (not WeaponsValue.Missiles.Value) then
			C1B.Parent.Visible = false
		end
		if WeaponsValue.Rockets.Value then
			C2B.Text = "Key: "..WeaponControls.FireRockets.Value:upper()
		elseif (not WeaponsValue.Rockets.Value) then
			C2B.Parent.Visible = false
		end
		if WeaponsValue.Guns.Value then
			C3B.Text = "Key: "..WeaponControls.FireGuns.Value:upper()
		elseif (not WeaponsValue.Guns.Value) then
			C3B.Parent.Visible = false
		end
		if WeaponsValue.Bombs.Value then
			C4B.Text = "Key: "..WeaponControls.DropBombs.Value:upper()
		elseif (not WeaponsValue.Bombs.Value) then
			C4B.Parent.Visible = false
		end
		if WeaponsValue.Flares.Value then
			C5B.Text = "Key: "..WeaponControls.DeployFlares.Value:upper()
		elseif (not WeaponsValue.Flares.Value) then
			C5B.Parent.Visible = false
		end
	end
	ControlsA.MouseButton1Click:connect(function()		if GuiAVisible then
			GuiAVisible = false
			FrameA:TweenPosition(UDim2.new(0,150,0,-190),"In","Quad",1,true)
		elseif (not GuiAVisible) then
			GuiAVisible = true
			FrameA:TweenPosition(UDim2.new(0,150,0,170),"Out","Quad",1,true)
		end
	end)
	ControlsB.MouseButton1Click:connect(function()
		if GuiBVisible then
			GuiBVisible = false
			FrameB:TweenPosition(UDim2.new(0,-150,0,-150),"In","Quad",1,true)
		elseif (not GuiBVisible) then
			GuiBVisible = true
			FrameB:TweenPosition(UDim2.new(0,-150,0,170),"Out","Quad",1,true)
		end
	end)
end

function GetRoll(CF)	local CFRight = CF * CFrame.Angles(0,math.rad(90),0)
	local CFNoRollRight = CFrame.new(CF.p,CF.p + CF.lookVector) * CFrame.Angles(0,math.rad(90),0)
	local CFDiff = CFRight:toObjectSpace(CFNoRollRight)
	return (-math.atan2(CFDiff.lookVector.Y, CFDiff.lookVector.Z) % (math.pi * 2) + math.pi)
end

function GetPitch(CF)	local LV = CF.lookVector
	local XZDist = math.sqrt(LV.x^2 + LV.z^2)
	return math.atan(LV.y / XZDist)
end

script.Parent.RenderSteppedEvent.OnServerEvent:Connect(function(player,mouse)
	if Selected then
		if (not LockedCam) then
			Camera.CameraType = CameraType2
		elseif LockedCam then
			local HeadCF = Character.Head.CFrame
			local PlaneSize = Plane:GetModelSize().magnitude/3
			local Origin = HeadCF.p + (HeadCF.lookVector * (PlaneSize - 1))
			local Target = HeadCF.p + (HeadCF.lookVector * PlaneSize)
			Camera.CameraType = Enum.CameraType.Scriptable
			Camera.CoordinateFrame = CFrame.new(Origin,Target)
			Camera:SetRoll(GetRoll(Character.Head.CFrame))
		end
	else
		Camera.CameraType = Enum.CameraType.Custom
	end
end)

function UpdateTargetStats(Target,Gui)
	if Target then
		local myHead = Character.Head
		local TorsoPos = Target.Character.Torso.CFrame
		local Distance = (myHead.CFrame.p - TorsoPos.p).magnitude
		local TargetSpeed = (Target.Character.Torso.Velocity).magnitude
		local TargetAlt = Target.Character.Torso.Position.Y
		Gui.LockName.Text = ("Target: %s"):format(Target.Name)
		Gui.Dist.Text = ("Distance: %s"):format(tostring(math.floor(Distance * 10)/10))
		Gui.Speed.Text = ("Speed: %s"):format(tostring(math.floor(TargetSpeed * 10)/10))
		Gui.Altitude.Text = ("Altitude: %s"):format(tostring(math.floor(TargetAlt * 10)/10))
	elseif (not Target) then
		Gui.LockName.Text = "Target: None"
		Gui.Dist.Text = "Distance: N/A"
		Gui.Speed.Text = "Speed: N/A"
		Gui.Altitude.Text = "Altitude: N/A"
	end
end

function UpdateHUD(Gui)
	Gui.Roll.Rotation = math.deg(GetRoll(Character.Head.CFrame))
	local PitchNum = math.deg(GetPitch(Character.Head.CFrame))/90
	Gui.Roll.Pitch.Position = UDim2.new(0,-200,0,-500 + (PitchNum * 450))
	local SpeedScaled = TrueAirSpeed/50
	Gui.Speed.Main.Position = UDim2.new(0,0,0.5,SpeedScaled * 75)
	Gui.Speed.Disp.Text.Text = RoundNumber(TrueAirSpeed)
	local AltScaled = RoundNumber(Engine.Position.Y)/500
	Gui.Altitude.Main.Position = UDim2.new(0,0,0.5,AltScaled * 75)
	Gui.Altitude.Disp.Text.Text = RoundNumber(Engine.Position.Y)
	local NegFactor = (Engine.Velocity.y/math.abs(Engine.Velocity.y))
	local VerticalSpeed = RoundNumber(math.abs(Engine.Velocity.y))
	Gui.ClimbRate.Text = ("VSI: %i"):format(VerticalSpeed * NegFactor)
	Gui.GearStatus.Text = (GearUp and "Gear Up" or "Gear Down")
	Gui.GearStatus.TextColor3 = (GearUp and Color3.new(0,1,0) or Color3.new(1,0,0))
	Gui.EngineStatus.Text = (EngineOn and "Engine On" or "Engine Off")
	Gui.EngineStatus.TextColor3 = (EngineOn and Color3.new(0,1,0) or Color3.new(1,0,0))
	Gui.StallWarn.Visible = ((not Taxi()) and Stall())
	Gui.PullUp.Visible = (EngineOn and (not Taxi()) and (AltRestrict.Value) and (Engine.Position.Y < (MinAltitude2 + 20)))
	Gui.TaxiStatus.Visible = (Engine and Taxi())
	Gui.Throttle.Bar.Tray.Position = UDim2.new(0,0,1,-(Throttle * 460))
	Gui.Throttle.Bar.Tray.Size = UDim2.new(1,0,0,(Throttle * 460))
	Gui.Throttle.Disp.Text = math.abs(math.floor(Throttle * 100)).."%"
	local StallLinePos = (StallSpeed2/math.floor(TrueAirSpeed + 0.5)) * (StallSpeed2/MaxSpeed2)
	local StallLinePosFix = (StallLinePos > 1 and 1 or StallLinePos < 0 and 0 or StallLinePos)
	Gui.Throttle.Bar.StallLine.Position = UDim2.new(0,0,1 - StallLinePosFix,0)
	Gui.Throttle.Bar.Tray.BackgroundColor3 = (Throttle <= StallLinePosFix and Color3.new(1,0,0) or Color3.new(0,1,0))
end

function UpdateGui(Taxiing,Stalling)
	local Gui = GuiClone.Main
	local TargetStats = GuiClone.Target
	local HUD = Player.PlayerGui.PlaneGui.HUD
	Gui.Visible = ((not HUDOnLock.Value) or (HUDOnLock.Value and (not LockedCam)))
	HUD.Visible = (LockedCam and HUDOnLock.Value)
	if LockedCam and HUDOnLock.Value then UpdateHUD(HUD) end
	if Targetable2 then UpdateTargetStats(TargetPlayer,TargetStats) end
	Gui.PullUp.Visible = (EngineOn and (not Taxiing) and (AltRestrict.Value) and (Engine.Position.Y < (MinAltitude2 + 20)))
	Gui.Taxi.Visible = (EngineOn and Taxiing)
	Gui.Stall.Visible = ((not Taxiing) and Stalling)
	Gui.Altitude.Text = "Altitude: "..RoundNumber(Engine.Position.Y)
	Gui.Speed.Text = "Speed: "..RoundNumber(TrueAirSpeed)
	Gui.Throttle.Bar.Tray.Size = UDim2.new(Throttle,0,1,0)
	Gui.Throttle.Percent.Text = math.abs(math.floor(Throttle * 100)).."%"
	local StallLinePos = (StallSpeed2/math.floor(TrueAirSpeed + 0.5)) * (StallSpeed2/MaxSpeed2)
	local StallLinePosFix = (StallLinePos > 1 and 1 or StallLinePos < 0 and 0 or StallLinePos)
	Gui.Throttle.Bar.StallLine.Position = UDim2.new(StallLinePosFix,0,0,0)
	Gui.Throttle.Bar.Tray.BackgroundColor3 = (Throttle <= StallLinePosFix and Color3.new(1,0,0) or Color3.new(0,2/3,0))
end

function CalculateSpeed()
	while Selected do
		if EngineOn then
			CurrentSpeed = (CurrentSpeed < DesiredSpeed and CurrentSpeed + 2 or CurrentSpeed - 2)
			CurrentSpeed = (CurrentSpeed < 0 and 0 or CurrentSpeed > MaxSpeed2 and MaxSpeed2 or CurrentSpeed)
		end
		wait(0.5 - (Acceleration2/2000))
	end
end

function GetLowestPoint()
	if (#LandingGear == 0) then
		LowestPoint = (Engine.Position.Y + 5 + (Engine.Size.Y/2))
		return
	end
	for i,v in pairs(LandingGear) do
		local Set0 = (Engine.Position.Y - (v.CFrame * CFrame.new((v.Size.X/2),0,0)).Y)
		local Set1 = (Engine.Position.Y - (v.CFrame * CFrame.new(-(v.Size.X/2),0,0)).Y)
		local Set2 = (Engine.Position.Y - (v.CFrame * CFrame.new(0,(v.Size.Y/2),0)).Y)
		local Set3 = (Engine.Position.Y - (v.CFrame * CFrame.new(0,-(v.Size.Y/2),0)).Y)
		local Set4 = (Engine.Position.Y - (v.CFrame * CFrame.new(0,0,(v.Size.Z/2))).Y)
		local Set5 = (Engine.Position.Y - (v.CFrame * CFrame.new(0,0,-(v.Size.Z/2))).Y)
		local Max = (math.max(Set0,Set1,Set2,Set3,Set4,Set5) + 5)
		LowestPoint = (Max > LowestPoint and Max or LowestPoint)
	end
end

function GetBankAngle(M)
	local VSX,X = M.ViewSizeX,M.X
	local Ratio = (((VSX/2) - X)/(VSX/2))
	Ratio = (Ratio < -1 and -1 or Ratio > 1 and 1 or Ratio)
	return math.rad(Ratio * MaxBank2)
end

function Taxi()
	local Ray = Ray.new(Engine.Position,Vector3.new(0,-LowestPoint,0))
	return (TrueAirSpeed <= StallSpeed2 and game.Workspace:FindPartOnRay(Ray,Plane))
end

function Stall()
	return ((AltRestrict.Value and Engine.Position.Y > MaxAltitude2) or TrueAirSpeed < StallSpeed2)
end

script.Parent.SteppedEvent.OnServerEvent:Connect(function(player,M)
	if Selected then
		local BankAngle = GetBankAngle(M)
		local Taxi,Stall = Taxi(),Stall()
		if EngineOn then
			Engine.Thrust.velocity = (Engine.CFrame.lookVector * CurrentSpeed) + Vector3.new(0,0.15,0)
			if Taxi then
				if (CurrentSpeed < 2) then
					Thrust.maxForce = Vector3.new(0,0,0)
					Direction.maxTorque = Vector3.new(0,0,0)
				else
					Thrust.maxForce = Vector3.new(math.huge,0,math.huge)
					Direction.maxTorque = Vector3.new(0,math.huge,0)
					Direction.cframe = CFrame.new(Engine.Position,script.Parent.mouse.Value)
				end
			elseif Stall then
				Thrust.maxForce = Vector3.new(0,0,0)
				Direction.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
				Direction.cframe = (M*CFrame.Angles(0,0,BankAngle))
			else
				Thrust.maxForce = Vector3.new(math.huge,math.huge,math.huge)
				Direction.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
				Direction.cframe = (M*CFrame.Angles(0,0,BankAngle))
			end
			if ((AltRestrict.Value) and (Engine.Position.Y < MinAltitude2)) then
				AutoCrash.Value = true
			end
		elseif (not EngineOn) then
			Thrust.maxForce = Vector3.new(0,0,0)
			Thrust.velocity = Vector3.new(0,0,0)
			Direction.maxTorque = Vector3.new(0,0,0)
		end
		TrueAirSpeed = Engine.Velocity.magnitude
		UpdateGui(Taxi,Stall)
		wait()
	end
end)

script.Parent.keyDownEvent.OnServerEvent:Connect(function(player,Key)
	Key = Key:lower()
	if (Key == FlightControls.Engine.Value) then
		local Gui = GuiClone.Main
		if (not EngineOn) then
			EngineOn = true
			DesiredSpeed = 0
			CurrentSpeed = 0
			Throttle = 0
			Gui.Engine.Visible = false
			CalculateSpeed()
		elseif EngineOn then
			EngineOn = false
			DesiredSpeed = 0
			CurrentSpeed = 0
			Throttle = 0
			Gui.Engine.Visible = true
		end
	end
	if (Key == FlightControls.Gear.Value) then
		local Gui = GuiClone.Main
		local Taxiing = Taxi()
		if (#LandingGear ~= 0) then
			if (not Taxiing) then
				ChangeGear()
				if (not GearUp) then
					GearUp = true
					Gui.Gear.Text = "Gear Up"
				elseif GearUp then
					GearUp = false
					Gui.Gear.Text = "Gear Down"
				end
			end
		end
	end
	if SUAK and Key:byte() == SpeedUp2 or (not SUAK) and (Key == SpeedUp2) then
		Accelerating = true
		IncreaseSpd()
	end
	if SDAK and Key:byte() == SlowDown2 or (not SDAK) and (Key == SlowDown2) then
		Decelerating = true
		DecreaseSpd()
	end
	if (Key == TargetControls.Modes.Value) then
		if Targetable2 then
			if EngineOn then
				if (not Targeting) then
					Targeting = true
				elseif Targeting then
					Targeting = false
					Locked = false
					AimGui.Enabled = false
					LockGui.Enabled = false
				end
			end
		end
	end
	if (Key == FlightControls.Eject.Value:lower()) then
		if EngineOn then
			local Taxiing = Taxi()
			if (not Taxiing) then
				if Ejectable.Value then
					if (not Plane.Ejected.Value) then
						Plane.Ejected.Value = true
						local Seat = MainParts.Seat
						local EjectClone = Tool.Ejector:clone()
						EjectClone.Parent = Player.PlayerGui
						EjectClone.Disabled = false
						local Fire = Instance.new("Fire")
						Fire.Parent = Engine
						Fire.Heat = 25
						Fire.Size = 30
						local Smoke = Instance.new("Smoke")
						Smoke.Parent = Engine
						Smoke.Color = Color3.new(1/3,1/3,1/3)
						Smoke.Opacity = 0.7
						Smoke.RiseVelocity = 10
						Smoke.Size = 10
						Seat.SeatWeld:remove()
					end
				end
			end
		end
	end
	if (Key == FlightControls.LockCam.Value) then
		LockedCam = (not LockedCam)
	end
	if (Key == WeaponControls.FireGuns.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Guns.Value then
				if EngineOn then
					local Taxiing = Taxi()
					if (not Taxiing) then
						FiringGun = true
						FireMachineGun(Weapons)
					end
				end
			end
		end
	end
	if (Key == WeaponControls.FireRockets.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Rockets.Value then
				local Taxiing = Taxi()
				if (not Taxiing) then
					if RocketEnabled then
						RocketEnabled = false
						FireRockets(Weapons)
						ReloadRocket(RocketTime2)
					end
				end
			end
		end
	end
	if (Key == WeaponControls.DeployFlares.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Flares.Value then
				if EngineOn then
					local Taxiing = Taxi()
					if (not Taxiing) then
						if FlareEnabled then
							FlareEnabled = false
							for i = 1,5 do
								DeployFlares(Weapons)
								wait(0.2)
							end
							ReloadFlare(FlareTime2)
						end
					end
				end
			end
		end
	end
	if (Key == WeaponControls.DropBombs.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Bombs.Value then
				if EngineOn then
					local Taxiing = Taxi()
					if (not Taxiing) then
						if BombEnabled then
							BombEnabled = false
							local BombSpawns = {}
							for i,v in pairs(Weapons:GetChildren()) do
								if v:IsA("BasePart") then
									if v.Name == "BombSpawn" then
										table.insert(BombSpawns,v)
									end
								end
							end
							local CurrentSpawn = BombSpawns[math.random(1,#BombSpawns)]
							if Locked then
								DropGuidedBomb(CurrentSpawn)
								ReloadBomb((BombTime2 * 2))
							elseif (not Locked) then
								for i = 1,5 do
									DropBomb(Weapons)
									wait(0.3)
								end
								ReloadBomb(BombTime2)
							end
						end
					end
				end
			end
		end
	end
	if (Key == WeaponControls.FireMissile.Value) then
		if WeaponsValue.Value then
			if WeaponsValue.Missiles.Value then
				if EngineOn then
					local Taxiing = Taxi()
					if (not Taxiing) then
						if MissileEnabled then
							MissileEnabled = false
							local MissileSpawns = {}
							for i,v in pairs(Weapons:GetChildren()) do
								if v:IsA("BasePart") then
									if v.Name == "MissileSpawn" then
										table.insert(MissileSpawns,v)
									end
								end
							end
							local CurrentSpawn = MissileSpawns[math.random(1,#MissileSpawns)]
							if Locked then
								FireGuidedMissile(CurrentSpawn)
								ReloadMissile((MissileTime2 * 2))
							elseif (not Locked) then
								FireMissile(CurrentSpawn)
								ReloadMissile(MissileTime2)
							end
						end
					end
				end
			end
		end
	end
	if (Key == TargetControls.UnTarget.Value) then
		if Targetable2 then
			if Locked then
				Locked = false
			end
		end
	end
end)

script.Parent.keyUpEvent.OnServerEvent:Connect(function(player,Key)
	Key = Key:lower()
	if SUAK and Key:byte() == SpeedUp2 or (not SUAK) and (Key == SpeedUp2) then
		Accelerating = false
	end
	if SDAK and Key:byte() == SlowDown2 or (not SDAK) and (Key == SlowDown2) then
		Decelerating = false
	end
	if (Key == WeaponControls.FireGuns.Value) then
		FiringGun = false
	end
end)

function onSelected(mouse)
	Selected = true
	mouse2 = mouse
	FixVars()
	GetGear(Gear)
	GetLowestPoint()
	ToolSelect.Value = true
	GuiClone = GUI:clone()
	GuiClone.Parent = Player.PlayerGui
	SetUpGui()
	Camera.CameraType = CameraType2
	if Targetable2 then
		AimGui = Instance.new("BillboardGui",Player.PlayerGui)
		AimGui.AlwaysOnTop = true
		AimGui.Enabled = false
		AimGui.Size = UDim2.new(0,50,0,50)
		local Label = Instance.new("ImageLabel",AimGui)
		Label.BackgroundTransparency = 1
		Label.Image = "http://www.roblox.com/asset/?id=107388694"
		Label.Size = UDim2.new(1,0,1,0)
		LockGui = Instance.new("BillboardGui",Player.PlayerGui)
		LockGui.AlwaysOnTop = true
		LockGui.Enabled = false
		LockGui.Size = UDim2.new(0,50,0,50)
		local Label = Instance.new("ImageLabel",LockGui)
		Label.BackgroundTransparency = 1
		Label.Image = "http://www.roblox.com/asset/?id=107388656"
		Label.Size = UDim2.new(1,0,1,0)
	end
	mouse.Icon = NormalCursor
	-- FTab[1] = mouse.Move:connect(function() onMouseMoved(mouse) end)
	-- FTab[2] = mouse.Idle:connect(function() onMouseMoved(mouse) end)
	-- FTab[3] = mouse.Button1Down:connect(function() onButton1Down(mouse) end)
	-- FTab[4] = mouse.KeyDown:connect(onKeyDown)
	-- FTab[5] = mouse.KeyUp:connect(onKeyUp)
	-- FTab[6] = RunService.RenderStepped:connect(UpdateCamera)
	-- FTab[7] = RunService.Stepped:connect(function() FlyMain(mouse) end)
end

function onDeselected(mouse)
	Selected = false
	LockedCam = false
	for i,v in pairs(FTab) do
		if v then
			v:disconnect()
		end
	end
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CameraSubject = Character.Humanoid
	if Targetable2 then
		AimGui:remove()
		LockGui:remove()
	end
	if (not Taxi()) and EngineOn then
		if (not Deselect0.Value) and (not Plane.Ejected.Value) then
			onDeselectFlying()
		end
	end
	CurrentSpeed = 0
	DesiredSpeed = 0
	TrueAirSpeed = 0
	EngineOn = false
	Updating = false
	Locked = false
	Targeting = false
	TargetPlayer = nil
	ToolSelect.Value = false
	GuiAVisible = true
	GuiBVisible = true
	GuiClone:remove()
	Engine.Thrust.velocity = Vector3.new(0,0,0)
	Engine.Thrust.maxForce = Vector3.new(0,0,0)
	Engine.Direction.maxTorque = Vector3.new(0,0,0)
end

function onDeselectFlying()
	if (not Deselect0.Value) then
		local Explosion = Instance.new("Explosion")
		Explosion.Parent = game.Workspace
		Explosion.Position = Engine.Position
		Explosion.BlastRadius = Plane:GetModelSize().magnitude
		Explosion.BlastPressure = 100000
		Character.Humanoid.Health = 0
		Engine.Thrust:remove()
		Engine.Direction:remove()
		script.Parent.PlaneGui.Enabled = false
		delay(5,function()
			Plane:Destroy()
		end)
	end
end

function onDeselectForced()
	if Deselect0.Value then
		onDeselected()
		mouse2.Icon = "rbxasset://textures\\ArrowCursor.png"
	end
end

script.Parent.Equipped:connect(onSelected)
script.Parent.Unequipped:connect(onDeselected)
Deselect0.Changed:connect(onDeselectForced)
-- LocalScript
mouse = game.Players.LocalPlayer:GetMouse()

mouse.Move:Connect(function()
	script.Parent.moveEvent:FireServer(mouse.Hit.Position)
end)

mouse.Idle:Connect(function()
	script.Parent.moveEvent:FireServer(mouse.Hit.Position)
end)

mouse.KeyDown:Connect(function(key)
	script.Parent.keyDownEvent:FireServer(key)
end)

mouse.KeyUp:Connect(function(key)
	script.Parent.keyUpEvent:FireServer(key)
end)

RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	script.Parent.RenderSteppedEvent:FireServer(mouse.Hit.Position)
end)

RunService.Stepped:Connect(function()
	script.Parent.SteppedEvent:FireServer(mouse.Hit)
end)
1 Like

testing it… 3030303030330303030303030303

@temporaryacount101 2500+ errors.

I am going to send it as a model, so you can look at it.