Script works, but it's telling me that "18:20:36.041 - Players.Player1.Backpack.Plane.Main:46: attempt to index global 'mouse' (a nil value)" When I Just defined it...
wait(0.1) -- Yes, this is needed. If it's not here, the plane will only work once.
local player = script.Parent.Parent.Parent
local mouseSave
local maxBank = 90
local gyro = script.Parent.Parent.Parent.Character.Real.Main.Gyro
function fly(m) -- Main function that controls all of the flying stuff. Very messy.
inputService = game:GetService("UserInputService")
SPEED =0
while true do
wait()
local enabled = true
Player = script.Parent.Parent.Parent
--Player:WaitForDataReady()
mouse = Player:GetMouse() ----RIGHT HERE D:
function onKeyDown(key)
if not enabled then return end
enabled = false
Key = key:lower()
if key == "w" then
SPEED = SPEED +1
print(SPEED)
local main = script.Parent.Parent.Parent.Character.Real.Main
local move = script.Parent.Parent.Parent.Character.Real.Main.Move
move.velocity = (main.CFrame.lookVector + main.CFrame.lookVector*SPEED) -- Set speed to aircraft
local bank = ((((m.ViewSizeX/2)-m.X)/(m.ViewSizeX/2))*maxBank) -- My special equation to calculate the banking of the plane. It's pretty simple actually
bank = (bank < -maxBank and -maxBank or bank > maxBank and maxBank or bank)
gyro.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
gyro.cframe = (m.Hit*CFrame.Angles(0,0,math.rad(bank)))
end
end
enabled = true
end
end
mouse.KeyDown:connect(onKeyDown)
script.Parent.Selected:connect(function(m) -- Initial setup
mouseSave = m
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Attach
m.Icon = "http://www.roblox.com/asset/?id=48801855" -- Mouse icon used in Perilous Skies
delay(0,function() fly(m) end) -- Basically a coroutine
end)

6 comments
Yes...
But the script still gives me the same error.
The only problem i see is that its inside the while loop. If i were you i'd leave it outside the loop and then call it and also add the loop inside the function
I edited the answer so you an see what im talking about
Wont work .-.
Really? Well ummm, the last thing i can only tell you is to rewrite your code (use the example above to make it look clean) but im guessing youre still going or might end up getting the same error. But before you do that, bring "mouse.KeyDown:connect(onKeyDown)" to the very last line of your code and define the "mouse" variable again but to the very first couple of lines before you make a function