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.
programming     games     scripting     roblox     gamepad     controller

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 UnbindAction 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...)
Calls func with name, InputS­tate, and InputO­bject when input­Types are used.
:UnbindAction(name)
Unbinds a function from action name.
Input types for :BindAction():
As soon as a player can use an input (like A/B, triggers, or thumbs­tick), use :Bind­Act­ion­(...). 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 :Unbi­ndA­cti­on(­name).

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")
   end
end

-- 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 (Beg­in, Chan­ge, End or Canc­el) and the InputObject. It's good practice to have just one action­-ha­ndling function per script.
 

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): GamepadEnabled
Returns true if at least one gamepad is connected.
Event: GamepadConnected
Fired when a gamepad is available.
Event:­Ga­mep­adD­isc­onn­ected
Fired when a gamepad is no longer available.
Avoid using UserI­npu­tSe­rvi­ce.I­np­utB­egan for actions involving button presses! Use Conte­xtA­cti­onS­erv­ice­:Bi­ndA­cti­on(...) 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 prim­ary character actions.
Left Trigger - Enum.K­eyC­ode.Bu­ttonL2
Use for seco­ndary character actions.
Right Thumbs­tick - Enum.K­eyC­ode.Th­umb­stick1
Use for camera movement.
Left Thumbs­tick - Enum.K­eyC­ode.Th­umb­stick2
Use for char­acter movement.
Righ­t/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.

Download the Roblox: Gamepad Input Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/ozzypig_roblox-gamepad-input.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors!

Readable.io is a collection of tools to make your writing better. More readable content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!

 

Comments

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: CFrames Cheat Sheet
          Roblox: General Scripting Cheat Sheet

          More Cheat Sheets by Ozzypig

          Roblox: CFrames Cheat Sheet
          Roblox: General Scripting Cheat Sheet