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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 14 Jun 2016 08:52 PM |
| DO NOT use KeyDown, use UnserInputService. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 17 Jun 2016 09:11 AM |
| DO NOT listen to him, use whatever suits you best ;) |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|