local UserInputService = game:GetService("UserInputService")
InputBegan → fires when input starts (key pressed, mouse clicked, touch began).
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end -- ignore if chat/menu handled it
if input.KeyCode == Enum.KeyCode.Space then
print("Spacebar pressed")
end
end)
InputEnded → fires when input stops (key released, mouse button lifted).
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
print("Spacebar released")
end
end)
InputChanged → fires when input changes (mouse moves, joystick tilts, touch moves).
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
print("Mouse moved:", input.Position)
end
end)
input.KeyCodeinput.UserInputType (e.g., MouseButton1, MouseMovement)UserInputType.TouchUserInputType.Gamepad1, buttons like Enum.KeyCode.ButtonA