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

I need help with scripting, can yall help me? i need help with detecting a keyboard button pressed

Asked by 5 years ago

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?

0
Input service. greatneil80 2647 — 5y

4 answers

Log in to vote
1
Answered by 5 years ago

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)
Ad
Log in to vote
1
Answered by
OBenjOne 190
5 years ago
Edited 5 years ago

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

0
Hmmm the links not working lemme try to fix it... OBenjOne 190 — 5y
0
Oh well, I guess you can just copy that and search it up OBenjOne 190 — 5y
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

welp now i aint answering any cus i already found a MUCH shrter version

0
but i will upvote alls yall :D Vortex_Vasne 89 — 5y

Answer this question