For thread safety, this property is not safe to read in an unsynchronized thread.
The GamepadDisconnected event fires when a gamepad is disconnected.
Since a Roblox game supports multiple controllers, this event is useful when paired with the
UserInputService/GamepadConnected event to track which controllers/gamepads are active. You can also use
UserInputService/GetConnectedGamepads to find the correct gamepad to use.
The following example demonstrates a usage example of a tracking when a gamepad is disconnected from the client.
local userInputService = game:GetService("UserInputService") local function GamepadDisconnected(gamepad) print("Player has unplugged controller: " .. tostring(gamepad)) end) userInputService.GamepadDisconnected:Connect(GamepadDisconnected)
As this event fires locally, it can only be used in a
See this page for articles on cross-platform development.
How to Use the Right Gamepad for Input
The following code sample is used in the default gamepad script, so if you are using the default controls you do not need to worry about this. If you are creating a custom script for handling gamepad controls, this is a good template for retrieving which
Enum/UserInputType|gamepad enum you should use as the primary gamepad controller.
This code looks for the lowest numbered
UserInputService/GetNavigationGamepad|navigation gamepad, and if no navigation gamepad is found, finds the lowest numbered
UserInputService/GetConnectedGamepad|connected gamepad. If there is no connected gamepad, we default to gamepad1. This ensures at least some gamepad will be able to do controls.