---Below: Only change at spaces where i say u have to xd
--but i made all functions Userfriendly for people like u alex xD



function fireB(Type,AmmoSource)
	wmissile = bin:findFirstChild("Bullet")
	missile = wmissile:clone()
	missile.CFrame = AmmoSource.CFrame
	if(smoke_at_gun == false) then missile.Smoke.Enabled = false end 
	missile.WeaponScript.Disabled = false

	WM = Instance.new("Model")
	WM.Name = "Bullet"
	WM.Parent = game.Players.LocalPlayer.Character
	missile.Parent = WM

	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = game.Players.LocalPlayer
	creator_tag.Name = "creator"
	creator_tag.Parent = missile

	missile.Owner.Value = vehicle
end

function fire(pln,spn)
	local missile = bin.Rocket:clone()
	missile.CFrame = spn.CFrame * CFrame.new(0, 0, -35)
	missile.Mesh.Scale = Vector3.new(0.3, 0.3, 0.4)-- Resizer in case :3
	missile.RocketScript.Disabled = false
	missile.Parent = game.Workspace 
	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = game.Players.LocalPlayer
	creator_tag.Name = "creator"
	creator_tag.Parent = missile
	--Rocket ID 
	--missile.Rocket_ID.Value = pln.Parts.Values.Pln_ID.Value
	--Da rest...
	missile.Owner.Value = pln
end 

function move(point, engine)--Move Settings. this makes sure that the plane moves correctly. [NOT TO CHANGE!]
	local origincframe = engine:findFirstChild("BodyGyro").cframe
	size = engine.Size

	target = engine.Position+((point - engine.Position).unit*100)
	local dir = (target - engine.Position).unit
	local spawnPos = engine.Position
	left = engine.CFrame*CFrame.new(-size.x/1, 0, 0).p
	right = engine.CFrame*CFrame.new(size.x/1, 0, 0).p
	md = (target - engine.Position).magnitude

	foebmd = engine.CFrame*CFrame.new(0, 0, -md).p
	toleft = (target -left).magnitude
	toright = (target -right).magnitude
	rot = 0.5 --((foebmd - target).magnitude/(5*10))
	local pos = spawnPos + (dir * 1)
	engine:findFirstChild("BodyGyro").maxTorque = Vector3.new(9000, 9000, 9000)
	if toleft< toright and toleft >rot and taxiing == false then
		engine:findFirstChild("BodyGyro").cframe = CFrame.new(pos,  pos + dir)*CFrame.fromAxisAngle( Vector3.new(0, 0, rot) , math.pi/ 40 )
	elseif toleft > toright and toright >rot and taxiing == false then
		engine:findFirstChild("BodyGyro").cframe = CFrame.new(pos,  pos + dir)*CFrame.fromAxisAngle( Vector3.new(0, 0,-rot) , math.pi/ 40 )
	else
		engine:findFirstChild("BodyGyro").cframe = CFrame.new(pos,  pos + dir)
	end
	wait(0.1)
	engine:findFirstChild("BodyGyro").maxTorque = Vector3.new(0, 0, 0)
	engine:findFirstChild("BodyGyro").cframe = origincframe
end


function computeDirection(vec)--finds the Direction of the place [NOT TO CHANGE!]
	local lenSquared = vec.magnitude * vec.magnitude
	local invSqrt = 1 / math.sqrt(lenSquared)
	return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end


function findPlane(player)--needed to find the plane. [NOT TO CHANGE!]
	local list = player.Character:GetChildren()
	for x = 1, #list do
		if (list[x].Name == "Plane") then
			local weld = list[x]:FindFirstChild("Parts"):FindFirstChild("Seat"):FindFirstChild("SeatWeld")
			if (weld ~= nil) and (weld.Part1.Name == "HumanoidRootPart") then
				print(list[x])
				return list[x]
			end
		end
	end
	return nil
end

function onFollow(mouse) --A function to Follow the mouse [NOT TO CHANGE!]
if(Mousefollow == false) and (on == true) then
	wait()
	Mousefollow = true
elseif(Mousefollow == true)then
	wait()
	Mousefollow = false
elseif(on == false) then 
Mousefollow = false
end
end

function onButton1Down(mouse)--this is... i forgot but dont change lol xD [NOT TO CHANGE!]
	if(Mousefollow == false) then
	return  
	elseif(on == false) and (Mousefollow == true) then 
	Mousefollow = false
	elseif(Mousefollow == true) and (on == false) then
	Mousefollow = false
	elseif(Mousefollow == true) and (on == true) then
	local vehicle = findPlane(game:GetService("Players").LocalPlayer)
	if vehicle ~= nil and debounce == false and planedebounce == false then
	debounce = true

	controlling = true

	while Mousefollow == true do---If a error at mouse then here!!
		wait()
		local engine = vehicle.Parts.Engine
		local position = mouse.Hit
		local target = position.p
		if engine ~= nil then
		move(target, engine)
		end
		if planedebounce == true or
		controlling == false then break end
	end
	wait(.1)
	debounce = false
	end
end
end

function onButton1Up(mouse)--The mouse function yeh a mouse function lol [NOT TO CHANGE!]
	controlling = false
end
function setup(p)
local pln = p
local PS = script.Parent.Parent.Parent.PlayerGui:findFirstChild("PlaneStats").Frame