generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: KeyDown Connection Line

Previous Thread :: Next Thread 
drew8732 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. drew8732
Joined: 01 Apr 2010
Total Posts: 1965
30 Nov 2013 02:11 PM
So:

local mouse = game.Players.LocalPlayer:GetMouse()?
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
30 Nov 2013 03:42 PM
oyus
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image