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)
To make it easier do something like this
local player = game.Players.LocalPlayer --saves you alot of time by not doing "script.Parent.Parent" and less errors local mouse = player:GetMouse()
im assuming you're doing this in a local script, right?
Example
local player = game.Players.LocalPlayer local mouse = player:GetMouse() function fly() onKeyDown() end function onKeydown(key) if key == "w" then --while loop inside end --or something similar like this end mouse.KeyDown:connect(onKeyDown)