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 not triggering :/

Previous Thread :: Next Thread 
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
11 Feb 2014 08:19 PM
mouse = game.Players.LocalPlayer:GetMouse ()
mouse.KeyDown:connect(function(key)
if key == 48 then
-- code
end
end)
It's basically detecting if you hit Shift, but it doesn't seem to trigger the code inside. Is there anything obviously wrong with this code?
Report Abuse
jonesj627 is not online. jonesj627
Joined: 06 Oct 2010
Total Posts: 1496
11 Feb 2014 08:24 PM
mouse = game.Players.LocalPlayer:GetMouse ()
mouse.KeyDown:connect(function(key)
if (key.byte) == 48 then
-- code
end
end)

i think i fixed it but i'm unsure
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
11 Feb 2014 08:24 PM
Key is the string "key" that was pressed. It looks like you're trying to check the key from its byte code. To do that, just use this:

if key:byte() == 48 then
-- code
end

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
11 Feb 2014 08:26 PM
Woah, didn't know that!
Report Abuse
ZirutoHellfire is not online. ZirutoHellfire
Joined: 16 Aug 2012
Total Posts: 4647
11 Feb 2014 08:39 PM
Isn't that the Shift key? Also where did you find this?
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
11 Feb 2014 08:44 PM
@ZirutoHellfire
Yes, that is the shift key. That's what he intended it to be too, if I read his post correctly. I would also assume that he wrote this script himself, he did not get it anywhere.

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
jmasterj10 is not online. jmasterj10
Joined: 19 Sep 2010
Total Posts: 735
12 Feb 2014 03:14 AM
Also shouldn't it be a Local Script?
Report Abuse
GOLDC3PO is not online. GOLDC3PO
Joined: 31 May 2011
Total Posts: 509
12 Feb 2014 07:33 AM
here you go:
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Torso") and game.Players.LocalPlayer.Character:findFirstChild("Humanoid")
local mouse = game.Players.LocalPlayer:GetMouse()
repeat wait() until mouse
mouse.KeyDown:connect(function(key)
if string.byte(key) == 48 then
--Do whatever here!
end
end)
mouse.KeyUp:connect(function(key)
if string.byte(key) == 48 then
--Key up so :)
end
end)
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
12 Feb 2014 08:48 AM
Why on earth did you wait for their character, head, and torso before starting the rest of the script??

Also, when you use a function and it returns nil, that nil won't magically turn into something else if you wait a bit (I am referring to your use of mouse = blahblahblah, repeat wait() until mouse). You need to keep on checking, or in other words you need to keep on re-calling that function.
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