Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to use keydown?

Asked by 9 years ago

How do I use keydown?

Im attempting to use this :

keyDown.Key == 'r'

2 answers

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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:

--From a LocalScript
local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(inst)
    if inst.KeyCode == Enum.KeyCode.R then
        print("'R' was pressed")
    end
end)
uis.InputEnded:connect(function(inst)
    if inst.KeyCode == Enum.KeyCode.LeftShift then
        print("Left Shift was released")
    end
end)
Ad
Log in to vote
0
Answered by 9 years ago

~~~~~~~~~~~~~~~~~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.

0
How would I answer and ask questions like adark above sorry If I seem to trouble or bother you but I'm currently new to the site. legomaster38 39 — 9y

Answer this question