There are a few duplicate code samples (for example under GetNavigationGamepads
) on this page that start out by saying: “The following code sample is used in the default gamepad script.” This isn’t true. The default Gamepad
script currently does this:
-- This function selects the lowest number gamepad from the currently-connected gamepad
-- and sets it as the active gamepad
function Gamepad:GetHighestPriorityGamepad()
local connectedGamepads = UserInputService:GetConnectedGamepads()
local bestGamepad = NONE -- Note that this value is higher than all valid gamepad values
for _, gamepad in pairs(connectedGamepads) do
if gamepad.Value < bestGamepad.Value then
bestGamepad = gamepad
end
end
return bestGamepad
end
I found this 2015 post from a Roblox engineer that the docs seem to based on but it looks outdated.
It’s confusing because I don’t know if I need to account for UserInputService:GetNavigationGamepads()
or not. Will a gamepad ever not be a “navigation gamepad” if it’s not manually set with UserInputService:SetNavigationGamepad()
?
It would also be helpful to know if there is only one gamepad connected, is it guaranteed to be Enum.UserInputType.Gamepad1
?
Page URL: https://create.roblox.com/docs/reference/engine/classes/UserInputService