Skip to main content

Controller

If you have taken the time to read through the API, you may have noticed that most methods have a controller parameter with the type of number?. Roblox supports up to 8 "gamepads" and as such, your game may experience up to 8 controllers (and you may want to support this by having different input axes for each controller).

local jump = Axis.input {
Enum.KeyCode.Space, -- any other inputs will be treated as controller 1
Enum.KeyCode.ButtonA,
}

In this example, let's say that we let 8 players play locally, each with their own character who may want to jump for whatever reason. You may write a system like this to handle each character:

local function jump()
for i = 1, 8 do
-- if standing on the ground ...
if jump:pressed(i) then
-- make their character jump
end
end
end

Remember that you can use UserInputService:GetConnectedGamepads() to get the number of connected controllers.


Almost all methods allow you to specify a controller like this, even move(), hold(), and read().