How do I detect when a player pressed the up arrow key?
Use this or
They keycode for the up arrow key is
Enum.KeyCode.Up
You can use UserInputService, which offers a multitude of functions to track user input.
From there, try using the :IsKeyDown() function, which will tell you if a certain key (in your case, the up arrow) is being held down/pressed. If it is, the function will return true.
Please search first before asking. Ten seconds on the search bar could’ve given you something useful. You should always perform searches before asking such basic questions.
-
-
InputBegan to run a function when the user passes input; check for Enum.KeyCode.Up in the InputObject (first parameter) and that gameProcessedEvent is false
-
InputEnded for the same thing except when the key is released
-
IsKeyDown to check if a key is currently being held
-
-
-
BindAction to bind a function to multiple input types
-
BindActionAtPriority if you need the above but with varied priorities
-
Use the first service and the first two noted functions. Event-driven systems are better than using loops, which I’m assuming will happen if you choose to look at IsKeyDown. Use that for other scenarios such as if you need to check if something is being held down after another key is pressed through InputBegan.
Try this, maybe it’ll help.
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gameProccessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Up then
-- add function
end
end
end)