drew8732
|
  |
| Joined: 01 Apr 2010 |
| Total Posts: 1965 |
|
|
| 30 Nov 2013 12:48 PM |
I'm making a flashlight script attatched to my gun. When the F key is pressed, a SpotLight within the handle of the gun should be enabled/disabled. This appears to work, but the connection line always returns in error, saying "mouse" is invalid. Here's my script:
local function onKeyDown(key) key:lower() if (key == "f") then if not debounce then debounce = true click:play() if not light.Enabled then light.Enabled = true elseif light.Enabled then light.Enabled = false debounce = false end end end end mouse.KeyDown:connect(onKeyDown) --This is where it breaks.
What's worng here? I took the function line & connection line directly from another KeyDown script, so is this some wierd glitch? |
|
|
| Report Abuse |
|
|
ForceSky
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 2379 |
|
|
| 30 Nov 2013 12:50 PM |
You have to index mouse.
local mouse = PUTPLAYERHERE:GetMouse()
--your function here pls
--connection shud wrk now d00d |
|
|
| Report Abuse |
|
|
drew8732
|
  |
| Joined: 01 Apr 2010 |
| Total Posts: 1965 |
|
|
| 30 Nov 2013 12:53 PM |
So add a line like:
mouse = script.Parent.Parent:GetMouse()? mouse = Script>Tool>Player>Player's mouse?
Could you tell me the proper heirarchy pl0x? |
|
|
| Report Abuse |
|
|
drew8732
|
  |
| Joined: 01 Apr 2010 |
| Total Posts: 1965 |
|
|
| 30 Nov 2013 01:55 PM |
Still can't get it to work, here's what I have:
player = game.Players:GetPlayerFromCharacter(user) mouse = player:GetMouse()
--"User" is properly defined when the tool is equipped.
The connection line from the script above still returns in error even though the mouse is properly indexed. |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 30 Nov 2013 02:00 PM |
| Is this in a LocalScript? You can't use GetMouse, or really any mouse-grabbing code inside a normal Script. |
|
|
| Report Abuse |
|
|
drew8732
|
  |
| Joined: 01 Apr 2010 |
| Total Posts: 1965 |
|
|
| 30 Nov 2013 02:02 PM |
| Yeah, it is a LocalScript. But the raycast for the gun itself won't function ingame without it being a local script. Is there any other method I can use for KeyDown? |
|
|
| Report Abuse |
|
|
qrrrq
|
  |
| Joined: 27 Jan 2013 |
| Total Posts: 1252 |
|
|
| 30 Nov 2013 02:09 PM |
| If it's in a LocalScript, just use game.Players.LocalPlayer |
|
|
| Report Abuse |
|
|
drew8732
|
  |
| Joined: 01 Apr 2010 |
| Total Posts: 1965 |
|
|
| 30 Nov 2013 02:11 PM |
So:
local mouse = game.Players.LocalPlayer:GetMouse()? |
|
|
| Report Abuse |
|
|
ForceSky
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 2379 |
|
| |
|