yea so i need help sorry for the title i am still learning scripting i am a noob at it how do i detect a keyboard key pressed?
✓ ANSWER ACCEPTED
I need help with scripting, can yall help me? i need help with detecting a keyboard button pressed
4 answers
✓ Accepted answer
You can use the UserInputService to detect when a key is pressed. For example:
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:Connect(function(key) -- when key is pressed
if key.KeyCode == Enum.KeyCode.Q then -- if key is *x* then...
--CODE
end
end)
I think this might help :) It shows you how to use all sorts of user input
https://developer.roblox.com/en-us/articles/introduction-to-input
2 comments
0
Hmmm the links not working lemme try to fix it...
0
Oh well, I guess you can just copy that and search it up
You would use UserInputService to detect keys being pressed down.
local InputService = game:GetService('UserInputService') -- Gets the input service
InputService.InputBegan:Connect(function(key) -- InputBegan runs when a key is pressed and the the variable 'key' will represent what was pressed
if key.KeyCode = Enum.KeyCode.TheKeyYouWant then -- Checks if the key is the one you want
--Code here
end
end)
If this helped you please mark it as answered :D
welp now i aint answering any cus i already found a MUCH shrter version
1 comment
0
but i will upvote alls yall :D
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Input service.