Kind of like this...
mouse.Button1Down:Connect(function()
end)
...but for a key?
Kind of like this...
mouse.Button1Down:Connect(function()
end)
...but for a key?
Hey alonzo12345,
KeyDown event for detecting when a key is pressed however, that event is not deprecated and there's an even better method of detecting keys. Let me introduce you to UserInputService. This is a service that you can use for input, as the name might suggest. It's I believe about the most efficient and easiest way of getting input from the keyboard at the moment. This Service is very easy to use so, just bare with me here. Here is the wiki page for it and all of it's methods/events/properties. Below is a personal example with some brief explanations of it:local uis = game:GetService("UserInputService") -- Declares a variable for the UserInputService.
uis.InputBegan:Connect(function(obj, gp) -- Anonymous function with a parameter of obj and gp and the event 'InputBegan' is triggered when any key on the keyboard is pressed.
if obj.KeyCode = Enum.KeyCode.Q and not gp then -- obj is the key that is pressed and gp is a boolean value to check if it's meant to be pressed or not. gp is basically used to see if the user was typing in chat while he/she pressed the key or if the key was intentionally pressed without typing in chat. The if statement will not let the rest of the code run if 'Q' was pressed while chatting in this scenario.
print("Q was pressed.") -- Simply prints 'Q was pressed.' when it is pressed.
end) -- end for the anonymous function. Make sure that parenthesis at the end is there because, that's how you end anonymous functions.
#Well, I hope I some-what helped you out with your issue and the methods I used above will be linked below.
Here is the link for the :GetService() page.
Here is the link for the Anonymous functions page.
Here is the link for normal functions.
Here is the link for UserInputService being used.
~~ KingLoneCat
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Uinps is bad use mouse.KeyDown:connect(function(key) if key=="q" then --dostuff end end) uinps will also activate when typing so you need more denounces for it also you can use KeyUp instead of KeyDown