Detect gamepads, read their buttons and sticks, and let console players navigate your GUI with VirtualCursorMode.
Keyboards have a Space bar. Phones have touch. Consoles have a gamepad — and a gamepad is a very different way to control things, especially a GUI. Roblox gives you the to read it and a ready-made virtual cursor so console can click your buttons without a mouse.
UserInputService.GamepadEnabled tells you if any gamepad is plugged in, and the GamepadConnected / GamepadDisconnected fire as plug in or unplug:
local UserInputService = game:GetService("UserInputService")
print("Gamepad present:", UserInputService.GamepadEnabled)
UserInputService.GamepadConnected:Connect(function(gamepadNumber)
print("Gamepad", gamepadNumber, "connected")
end)
UserInputService.GamepadDisconnected:Connect(function(gamepadNumber)
print("Gamepad", gamepadNumber, "disconnected")
end)
GamepadEnabled is a snapshot — good for a one-time check. The are better when you need to react (show a controller icon, pause, or skip the button-tutorial).
The property that tells you whether a gamepad is currently plugged in is .
InputBegan fires for gamepad buttons exactly like it does for keys. The trick: gamepad inputs have a UserInputType of Gamepad1, Gamepad2, and so on, and their KeyCode is the button or stick.
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.ButtonA then
print("A pressed!")
end
end
end)
Sticks aren't discrete presses — they're continuous axes. Read them every frame with RunService and GetGamepadState, or better, bind them as ContextActionService actions (next step) so movement works the same as a keyboard.
When a Gamepad1 button is pressed, what is input.UserInputType?
Raw gamepad reading is fragile — every button name differs from a key. Prefer ContextActionService, which maps an action to both a key and a gamepad button:
ContextActionService:BindAction("jump", onJump, false,
Enum.KeyCode.Space, -- keyboard
Enum.KeyCode.ButtonA -- gamepad
)
One action, two input devices, one handler. This is the clean way to support controllers — you describe the action, and Roblox fires it whether the presses Space or A.
Hard-coding ButtonA in bare InputBegan code works, but breaks the moment you want keyboard + gamepad together. Bind the action once and let ContextActionService translate across devices.
A mouse moves a cursor; a gamepad doesn't. That's why console menus need a virtual cursor — a controller-driven highlight that moves between buttons. Enable it on StarterGui:
local StarterGui = game:GetService("StarterGui")
StarterGui.VirtualCursorMode = Enum.VirtualCursorMode.Enabled
The has three values:
Default (0) — let Roblox decide based on the device.Disabled (1) — never show a cursor.Enabled (2) — show the virtual cursor so gamepad and touch can navigate.Turn it on and the D-pad / left stick moves the highlight, and A (gamepad) or tapping (touch) activates the focused button — your existing Activated handlers just work.
Which mode makes the virtual cursor show so gamepad players can use your menus?
Putting it together — detect the gamepad, bind a shared action, and enable the cursor so the same shop menu works on console:
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local StarterGui = game:GetService("StarterGui")
if UserInputService.GamepadEnabled or UserInputService.TouchEnabled then
StarterGui.VirtualCursorMode = Enum.VirtualCursorMode.Enabled
end
ContextActionService:BindAction("buy", onBuy, true,
Enum.KeyCode.Space, Enum.KeyCode.ButtonA, Enum.UserInputType.Touch
)
A game with controller players needs a virtual cursor. Enable VirtualCursorMode from StarterGui.
local StarterGui = game:GetService("StarterGui")
-- turn on the virtual cursorButtonA/the stick — don't lock out keyboard .GamepadEnabled or TouchEnabled.Gamepad1 is the first controller, and multiple each have their own number.Next: shaping your sessions with PlayerAdded and the full lifecycle.