How do I use keydown?
Im attempting to use this :
1 | keyDown.Key = = 'r' |
Like anything else in ROBLOX, you have to listen to an Event. In this case, you're specifically looking for the KeyDown
Event of Mouse
objects.
Although, I would actually suggest using the UserInputService
instead, as it's a bit more... developed and has fewer complexities:
01 | --From a LocalScript |
02 | local uis = game:GetService( "UserInputService" ) |
03 |
04 | uis.InputBegan:connect( function (inst) |
05 | if inst.KeyCode = = Enum.KeyCode.R then |
06 | print ( "'R' was pressed" ) |
07 | end |
08 | end ) |
09 | uis.InputEnded:connect( function (inst) |
10 | if inst.KeyCode = = Enum.KeyCode.LeftShift then |
11 | print ( "Left Shift was released" ) |
12 | end |
13 | end ) |
~~~~~~~~~~~~~~~~~Another answer would be
~~~~~~~~~~~~~~~~~Not using UserInputService For an example you can use such thing such as just normal KeyDown event. mouse = game.Players.LocalPlayer:GetMouse() -----Getting the mouse from LocalPlayer function KeyDown(key)----Making an argument such as key if key:lower() == "r" then-----Checking if you pressed r and it was lower case print("You pressed r")-------Code you want to make happen once the event is fired. end----Two ends end---Two ends mouse.KeyDown:connect(KeyDown)---------The connection line to connect the event to it's appropriate event.