Show Menu

Roblox: Gamepad Input Cheat Sheet by

A quick reference for implementing gamepad (controller) input on Roblox. This cheatsheet is written for intermediate scripters.

Contex­tAc­tio­nSe­rvice basics

Used for binding to inputs gracef­ully. If an input is bound to one action and another action is to use the same button, the BindAction and Unbind­Action functions will handle the collision properly. Example: (A) could make the player jump OR open a door but only when close enough.
Each input type bound to a function using BindAction works like a stack: whichever function was the most recent to be bound will be called when that input type is activated by the player.

Contex­tAc­tio­nSe­rvice binding

:BindAction(name, func, touchButton, inputTypes...)
, InputS­tate, and InputO­bject when
are used.
Unbinds a function from action
Input types for
As soon as a player can use an input (like A/B, triggers, or thumbs­tick), use
. This will override the given input types current actions with the new one. When the player can no longer use the input for the action, use

Contex­tAc­tio­nSe­rvice example

local cas = game:GetService("ContextActionService")
function handleAction(actionName, inputState, inputObject)
   if actionName == "Swing sword" and inputState == Enum.UserInputState.Begin then
      print("Swinging sword")

-- When the sword is equipped:
cas:BindAction("Swing sword", handleAction, false, Enum.KeyCode.ButtonA)
-- When the sword is unequipped:
cas:UnbindAction("Swing sword")
When the given input type is activa­ted­/ch­anged, the function passed to :BindA­cti­on(...) is called with the action name, the input state (Begin, Change, End or Cancel) and the InputO­bject. It's good practice to have just one action­-ha­ndling function per script.

Wiki References


Gamepad KeyCodes and UserIn­put­Types

Buttons use the UserIn­put­States Began/End. Triggers and thumbs­ticks use Change.

UserIn­put­Service querying

Property (boolean):
Returns true if at least one gamepad is connected.
Fired when a gamepad is available.
Fired when a gamepad is no longer available.
Avoid using
for actions involving button presses!
because this "­ove­rri­des­" existing actions using the given input types, and properly returns control to existing actions when yours are unbound.

Tips and Good Practices

A Button - Enum.K­eyC­ode.Bu­ttonA
Bound to jump by default. Should be used as accept button for prompts.
B Button - Enum.K­eyC­ode.Bu­ttonB
Should be used as back or cancel button for menus/­pro­mpts.
Right Trigger - Enum.K­eyC­ode.Bu­ttonR2
Use for primary character actions.
Left Trigger - Enum.K­eyC­ode.Bu­ttonL2
Use for secondary character actions.
Right Thumbstick - Enum.K­eyC­ode.Th­umb­stick1
Use for camera movement.
Left Thumbstick - Enum.K­eyC­ode.Th­umb­stick2
Use for character movement.
Right/Left Bumpers - Enum.K­eyC­ode.Bu­tto­nR1­/Bu­ttonL1
Bound to switch tools by default.
A good way to know what kinds of control schemes work is by playing other gamepa­d/c­ont­roller enabled games.


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Roblox: General Scripting Cheat Sheet
          Roblox: CFrames Cheat Sheet

          More Cheat Sheets by Ozzypig

          Roblox: General Scripting Cheat Sheet
          Roblox: CFrames Cheat Sheet