📘 UserInputService Notes (Roblox Studio)

🔹 Purpose


🔹 Getting the Service

local UserInputService = game:GetService("UserInputService")


🔹 Main Events

  1. 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)
    
    
  2. 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)
    
    
  3. 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)
    
    

🔹 Checking Input


🔹 Useful Functions