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 » Scripters
Home Search
 

Re: KeyCode Space?

Previous Thread :: Next Thread 
Lem0nzzx is not online. Lem0nzzx
Joined: 08 Feb 2016
Total Posts: 1604
14 Jun 2016 07:51 PM
I rarely use keys other than the letters on my keyboard. But when I need to, I run into problems of how to do these sorts of things. How can I check to see if the key is space?

function pressed(key)
if key == then
print("Test")
end
end
mouse.KeyDown:connect(pressed)
Report Abuse
Lem0nzzx is not online. Lem0nzzx
Joined: 08 Feb 2016
Total Posts: 1604
14 Jun 2016 08:01 PM
I wanna know how I can check if a player pressed space.
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
14 Jun 2016 08:03 PM
uis = game:GetService'UserInputService'

uis.InputBegan:connect(function(input, event)
if event then return end
if input.KeyCode == Enum.KeyCode.Space
-- blah
end
end)


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
14 Jun 2016 08:03 PM
local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(input,event)
if event then return end
if input.KeyCode == Enum.KeyCode.Space then
print("Pressing Space")
end
end)


Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
14 Jun 2016 08:03 PM
The KeyCode for Space is Enum.KeyCode.Space.
But since you're using the far obsolete and inferior KeyDown, that won't work and I don't know what you would use. Use UserInputServie or ContextActionServie instead.
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
14 Jun 2016 08:04 PM
TimeTicks stole my intellectual property and added a print()!
hnnnnnnnnnggg


Report Abuse
darkjediwarriorX is not online. darkjediwarriorX
Joined: 26 Aug 2015
Total Posts: 879
14 Jun 2016 08:49 PM
First, you'd need to find the code for space, create a localscript with this code

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(key)

Print("KEY: "..key.." BYTE: "..string.byte(key))

end)

Find the BYTE for spacebar

Then in your script it would be

If string.byte(key) == BYTE for spacebar Then

-blargh
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
14 Jun 2016 08:52 PM
DO NOT use KeyDown, use UnserInputService.
Report Abuse
Lem0nzzx is not online. Lem0nzzx
Joined: 08 Feb 2016
Total Posts: 1604
15 Jun 2016 01:05 AM
My KeyDown was just an example of what I needed sorry. Thanks for the info though.
Report Abuse
darkjediwarriorX is not online. darkjediwarriorX
Joined: 26 Aug 2015
Total Posts: 879
17 Jun 2016 09:11 AM
DO NOT listen to him, use whatever suits you best ;)
Report Abuse
Lem0nzzx is not online. Lem0nzzx
Joined: 08 Feb 2016
Total Posts: 1604
17 Jun 2016 09:12 AM
LOL this post was 3 days ago where are you at?
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 Jun 2016 09:34 AM
depending on the scale that key presses have in your game, use either context action service(cas) or user input service(uis)

I use UIS mostly but they are both good in their own way.

-amanda
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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