GamepadService

Show Deprecated
Not Creatable
Service
Not Replicated

The GamepadService is internally responsible for handling inputs from various controllers, such as Xbox One or PlayStation DualShock controllers. It also handles APIs used with the gamepad virtual cursor. You can enable the gamepad cursor for your experience by setting Enum.VirtualCursorMode under StarterGui to Enabled.

Summary

Properties

Methods

Properties

GamepadCursorEnabled

Read Parallel
Roblox Script Security

This boolean is a read only variable that maintains the state of the gamepad virtual cursor.

Code Samples

GamepadService - Gamepad Cursor Enabled Property

local gamepadService = game.GamepadService
gamepadService:GetPropertyChangedSignal("GamepadCursorEnabled"):Connect(function()
local enabled = gamepadService.GamepadCursorEnabled
if enabled then
-- Custom code when the virtual cursor is enabled
else
-- Custom code when the virtual cursor is disabled
end
end)

Methods

DisableGamepadCursor

void

This function disables the gamepad cursor, if it's currently enabled.


Returns

void

Code Samples

GamepadService - Disable Gamepad Cursor

local gamepadService = game.GamepadService
local userInputService = game.UserInputService
userInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.ButtonB then
gamepadService:DisableGamepadCursor()
end
end)

EnableGamepadCursor

void

This function enables the gamepad cursor if it's currently disabled. If the cursor is already enabled, calling the API updates the cursor's position. The function accepts a GuiObject parameter, but there are some invalid cases. Please note that in order to set the cursor to the default position, nil must be passed in as a parameter. Providing no argument will result in an error.

Input GuiObjectCursor Starting Position
NilDefault position
Not a GuiObjectCursor does not appear, errors
Not a child of BasePlayerGuiCursor does not appear, errors
GuiObject has Visible 2 set to false or any parent visible set to falseDefault position with warning
Child of ScreenGui 1 with Enabled 1 set to falseDefault position with warning
Child of BillboardGui 4 or SurfaceGuiDefault position with warning
GuiObject outside the viewport (Or, any part of the gui object that is off screen)Default position with warning
Child of ScrollingFrame with clipping set to false: GuiObject outside of scrolling frame (Object child of scrolling frame and not visible on screen)Default position with warning
Child of ScrollingFrame with clipping set to true: GuiObject outside scrolling frame window but inside viewportGuiObject moves into the scrolling frame and starts the cursor centered over the object
GuiObject inside the frame and visibleCursor starts centered on the GuiObject

Parameters

guiObject: Instance

Returns

void

Code Samples

GamepadService - Enable Gamepad Cursor

local gamepadService = game.GamepadService
local userInputService = game.UserInputService
local startObject = script.Parent
userInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.ButtonA then
gamepadService:EnableGamepadCursor(startObject)
end
end)

Events