Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to use keydown?

How do I use keydown?

Im attempting to use this :

keyDown.Key == 'r'

2 answers

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)

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

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.