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

Can someone give me the key board button 1 down function?

Asked by 7 years ago

I want a function where if you click a key on your keyboard example: "Q" it will open up something. Now we all know there is a Touched function and a MouseButton1Down function, how do I do a keyboard function? Please write the answer like this;

Using MouseButton1Down as example, I want the keyboard function

MouseButton1Down:connect(function()
-- The function
end)

Please, I have been looking for a way to do this. Remember! I want a keyboard button down ish function, I don't know the function

1 answer

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

Using the wiki and google is always a good idea.

Use UserInputService.

Here's an example of it in action:

-- From Local Script:

--// Services
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gpe)
    if(input.KeyCode==Enum.KeyCode.Q)then
        -- The rest of the code.
        print("Q was pressed.")
    end
end)
Remember, you can only use this function on the client, via a LocalScript.
Ad

Answer this question