Detecting keyboard presses?

Hi, how can I detect if the space bar is pressed? I’m trying to use it for using items.

Use UserInputService | Documentation - Roblox Creator Hub to detect player keystrokes.

3 Likes

function KeyPress(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space then
print(“Space was pressed”)
end
end

game:GetService(“UserInputService”).InputBegan:Connect(KeyPress)

2 Likes

Thanks for the API class!!! That’ll help in the future since I know where it’s under!

1 Like