|
| 17 Jul 2014 07:52 AM |
So i have a script that when you press a certain key(e) that it should print something. But it keeps on saying in output that mouse is a nil value. Heres the script.
print("Ok you're good too go")
f=enabled function onKeyDown(key) key:lower() if key == "e" then if f ~= true then return end f = false print("It worked!") end end f=true Mouse.KeyDown:connect(onKeyDown) |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 08:03 AM |
Define the mouse, an example would be: Mouse = game.Players.LocalPlayer:GetMouse() Assuming you're using a LocalScript. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 08:30 AM |
| But im using a key wouldnt i have to define that not the mouse. Also its not a LocalScript. An example would be Im trying to make a note that when you press e a gui pops up and when you press e again it dissapears. |
|
|
| Report Abuse |
|
|
BlupoV2
|
  |
| Joined: 12 Nov 2012 |
| Total Posts: 543 |
|
|
| 17 Jul 2014 08:33 AM |
| You can only use the KeyDown Event on Mouse. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 08:34 AM |
| Alright, so why does it says mouse=nil in the output? |
|
|
| Report Abuse |
|
|
BlupoV2
|
  |
| Joined: 12 Nov 2012 |
| Total Posts: 543 |
|
|
| 17 Jul 2014 08:36 AM |
Did you define it?
i.e.
Mouse = [player]:GetMouse()
? |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 08:39 AM |
| Where is the script located?. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 08:40 AM |
| Inside of a Model called Paper |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 08:41 AM |
Alternatively, you could use something like, for i,v in pairs(game.Players:GetPlayers()) do Mouse = v:GetMouse() end This would globally effect each player however you can just create a function and utilize an event to get the individual player if necessary. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 08:45 AM |
| This will do just fine, Its a 1 player server game. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 08:48 AM |
| Where would this fit into the script? |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Jul 2014 09:08 AM |
--Alright, you'll probably need to adjust this later however, print("Ok you're good too go") f=true function onKeyDown(key) key:lower() if key == "e" then if f ~= true then return end f = false print("It worked!") end end f=true
while wait() do for i,v in pairs(game.Players:GetPlayers()) do Mouse = v:GetMouse() Mouse.KeyDown:connect(onKeyDown) end end
|
|
|
| Report Abuse |
|
|