bin=script.Parent
speed= 3
plane=nil
hold=false
local debounce = false
local planedebounce = false
local stuntdebounce = false
local controlling = false
function fire(pln,spn)
local missile = bin.Rocket:clone()
missile.CFrame = spn.CFrame * CFrame.new(0, 0, -35)
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
missile.Owner.Value = pln
end
function computeDirection(vec)
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 move(target, engine)
local origincframe = engine:findFirstChild("BodyGyro").cframe
local dir = (target - engine.Position).unit
local spawnPos = engine.Position
local pos = spawnPos + (dir * 1)
engine:findFirstChild("BodyGyro").maxTorque = Vector3.new(9000, 9000, 9000)
engine:findFirstChild("BodyGyro").cframe = CFrame.new(pos, pos + dir)
wait(0.1)
engine:findFirstChild("BodyGyro").maxTorque = Vector3.new(0, 0, 0)
engine:findFirstChild("BodyGyro").cframe = origincframe
end
function findPlane(player)
local list = player.Character:GetChildren()
for x = 1, #list do
if (list[x].Name == "Plane") then
local weld = list[x]:FindFirstChild("Parts"):FindFirstChild("Seat"):Fi ndFirstChild("SeatWeld")
if (weld ~= nil) and (weld.Part1 == player.Character:FindFirstChild("Torso")) then
return list[x]
end
end
end
return nil
end
function onButton1Down(mouse)
local vehicle = findPlane(script.Parent.Parent.Parent)
if vehicle ~= nil and debounce == false and planedebounce == false then
debounce = true
controlling = true
while true do
wait()
local engine = vehicle.Parts.Engine
local position = mouse.Hit
local target = position.p
if engine:findFirstChild("FlyScript") ~= nil then
move(target, engine)
end
if planedebounce == true or
controlling == false then break end
end
wait(.1)
debounce = false
end
end
function onButton1Up(mouse)
controlling = false
end
function onSelected(mouse)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
mouse.Button1Up:connect(function() onButton1Up(mouse) end)
mouse.KeyDown:connect(onKeyDown)
end
function onKeyDown(key)
if (key~=nil) then
key = key:lower()
local vehicle = findPlane(script.Parent.Parent.Parent)
if (vehicle==nil) then return end
plane = vehicle.Parts
local engine = vehicle.Parts.Engine
local r1 = engine.Parent.r1
local r2 = engine.Parent.r2
local l1 = engine.Parent.l1
local l2 = engine.Parent.l2
if (key=="f") and (bin.Reload.Value == 0) then--NA/Gun
fire(vehicle,plane.Gun1)
fire(vehicle,plane.Gun2)
bin.Reload.Value = 1
wait(1)
bin.Reload.Value = 0
end
if (key=="w") and planedebounce == false then--stop
local power = plane.Engine:findFirstChild("FlyScript")
if (power ~= nil) then
power:remove()
end
r1.RightParamB= 0
r1.RightParamA= 0
r2.RightParamB= 0
r2.RightParamA= 0
l1.RightParamB= 0
l1.RightParamA= 0
l2.RightParamB= 0
l2.RightParamA= 0
end
if (key=="q") then--Go
local power = plane.Engine:findFirstChild("FlyScript")
if (power ~= nil) then return end
local fly = script.FlyScript:clone()
fly.Disabled = true
fly.Parent = plane.Engine
r1.RightParamB= speed*-1
r1.RightParamA= speed
r2.RightParamB= speed*-1
r2.RightParamA= speed
l1.RightParamB= speed
l1.RightParamA= speed*-1
l2.RightParamB= speed
l2.RightParamA= speed*-1
end
if (key=="k") and planedebounce == false then--NA
wait()
engine.RotVelocity = Vector3.new(0, engine.RotVelocity.y -0.7, 0)
wait()
engine.RotVelocity = Vector3.new(0, engine.RotVelocity.y -0.7, 0)
wait()
engine.RotVelocity = Vector3.new(0, engine.RotVelocity.y -0.7, 0)
wait()
engine.RotVelocity = Vector3.new(0, engine.RotVelocity.y -0.7, 0)
end
if (key=="h") and planedebounce == false then--NA
wait()
engine.RotVelocity = Vector3.new(0, engine.RotVelocity.y +0.7, 0)
wait()
engine.RotVelocity = Vector3.new(0, engine.RotVelocity.y +0.7, 0)
wait()
engine.RotVelocity = Vector3.new(0, engine.RotVelocity.y +0.7, 0)
wait()
engine.RotVelocity = Vector3.new(0, engine.RotVelocity.y +0.7, 0)
return end
if (key=="y") and planedebounce == false then--jump backwards
local body = plane.Engine.BodyGyro
body.maxTorque = Vector3.new(9000, 9000, 9000)
local position = engine.CFrame * Vector3.new(0, 0.5, -4)
local dir = position - engine.Position
dir = computeDirection(dir)
local spawnPos = engine.Position
local pos = spawnPos + (dir * 8)
body.cframe = CFrame.new(pos, pos + dir)
wait(.2)
body.maxTorque = Vector3.new(0, 0, 0)
end
if (key=="l") and planedebounce == false then--NA
local body = plane.Engine.BodyGyro
body.maxTorque = Vector3.new(9000, 0, 0)
local frame = plane:FindFirstChild("OriginCFrame")
if frame ~= nil then
body.cframe = frame.Value
end
wait(0.1)
body.maxTorque = Vector3.new(0, 0, 0)
end
if (key=="u") and planedebounce == false then--jump forwards
local body = plane.Engine.BodyGyro
body.maxTorque = Vector3.new(9000, 9000, 9000)
local position = engine.CFrame * Vector3.new(0, -0.5, -4)
local dir = position - engine.Position
dir = computeDirection(dir)
local spawnPos = engine.Position
local pos = spawnPos + (dir * 8)
body.cframe = CFrame.new(pos, pos + dir)
wait(.2)
body.maxTorque = Vector3.new(0, 0, 0)
end
if (key=="b") and planedebounce == false and stuntdebounce == false then--kickflip
planedebounce = true
stuntdebounce = true
plane.Parent.Stunt.Value = 1
local body = plane.Engine.BodyGyro
body.maxTorque = Vector3.new(9000, 9000, 9000)
local currentframe = plane.Engine.CFrame
for i = 1,6 do
body.cframe = plane.Engine.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 30)
wait(.2)
end
body.cframe = currentframe
wait(.6)
body.maxTorque = Vector3.new(0, 0, 0)
planedebounce = false
plane.Parent.Stunt.Value = 0
wait(3)
stuntdebounce = false
end
if (key=="n") and planedebounce == false and stuntdebounce == false then--180 varial kickflip
planedebounce = true
stuntdebounce = true
plane.Parent.Stunt.Value = 1
local body = plane.Engine.BodyGyro
body.maxTorque = Vector3.new(9000, 9000, 9000)
local currentframe = plane.Engine.CFrame
local valy = 30
local valz = 30
for i = 1,8 do
body.cframe = currentframe * CFrame.fromEulerAnglesXYZ(0, valy, valz)
valy = valy +50
valz = valz +100
wait(.1)
end
body.cframe = currentframe * CFrame.fromEulerAnglesXYZ(0, 600, 0)
wait(.5)
body.maxTorque = Vector3.new(0, 0, 0)
planedebounce = false
plane.Parent.Stunt.Value = 0
wait(4)
stuntdebounce = false
end
if (key=="e") then-- Backwards
r1.RightParamB= speed
r1.RightParamA= speed*-1
r2.RightParamB= speed
r2.RightParamA= speed*-1
l1.RightParamB= speed*-1
l1.RightParamA= speed
l2.RightParamB= speed*-1
l2.RightParamA= speed
end
if (key=="m") and planedebounce == false then--90 degree spazfit
wait()
engine.BodyGyro.maxTorque = Vector3.new(9000, 9000, 9000)
engine.Velocity = Vector3.new(0, 50, 0)
wait(1)
engine.BodyGyro.maxTorque = Vector3.new(0, 0, 0)
engine.Velocity = Vector3.new(0, 0, 0)
end
end
end
bin.Selected:connect(onSelected)