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