Gamepad Documentation Incorrect/Outdated

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

2 Likes

Hi!

Thanks for pointing this out. UserInputService:GetNavigationGamepads() is quite old, I wouldn’t worry too much about this.

In general, if there’s only one gamepad connected, you can just use Enum.UserInputType.Gamepad1. The only time that might change is if other gamepads are connected, then the first gamepad is disconnected, but that’s not a common use case.

Also note that if you’re using ContextActionService, you can bind to all Gamepad enums to whatever code you’re trying to run.

Thanks

1 Like