Detect when player pressed the up arrow

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

1 Like

I,m not the best at explaining this topic but here is a video that should give you the basics.

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.

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.

1 Like

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)
1 Like