Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Cant get player mouse. But I defined it. Is this correct? [Unsolved]

Asked by 10 years ago

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...

01wait(0.1)   -- Yes, this is needed. If it's not here, the plane will only work once.
02local player = script.Parent.Parent.Parent
03local mouseSave
04local maxBank = 90
05local gyro = script.Parent.Parent.Parent.Character.Real.Main.Gyro
06 
07function fly(m) -- Main function that controls all of the flying stuff. Very messy.
08                inputService = game:GetService("UserInputService")
09 
10SPEED =0
11while true do
12    wait()
13local enabled = true
14Player = script.Parent.Parent.Parent
15--Player:WaitForDataReady()
View all 57 lines...

1 answer

Log in to vote
1
Answered by 10 years ago

To make it easier do something like this

1local player = game.Players.LocalPlayer --saves you alot of time by not doing "script.Parent.Parent" and less errors
2local mouse = player:GetMouse()

im assuming you're doing this in a local script, right?

Example

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03 
04function fly()
05    onKeyDown()
06end
07 
08function onKeydown(key)
09    if key == "w" then
10        --while loop inside
11    end --or something similar like this
12end
13 
14mouse.KeyDown:connect(onKeyDown)
0
Yes... Orlando777 315 — 10y
0
But the script still gives me the same error. Orlando777 315 — 10y
0
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 CMVProduction 25 — 10y
0
I edited the answer so you an see what im talking about CMVProduction 25 — 10y
View all comments (2 more)
0
Wont work .-. Orlando777 315 — 10y
0
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 CMVProduction 25 — 10y
Ad

Answer this question