ContextActionService

Show Deprecated
Not Creatable
Service

ContextActionService is a game service that allows a game to bind user input to contextual actions, or actions that are only enabled under some condition or period of time. For example, allowing a player to open a door only while close by. In code, an action is simply a string (the name of the action) used by the service to differentiate between unique actions. The action string is provided to BindAction and UnbindAction, among other member functions. If two actions are bound to the same input, the most recently bound will take priority. When the most recent action is unbound, the one bound before that takes control again. Since ContextActionService deals with user input, you can only use it in LocalScripts which run on the client.

What is a context?

A context is simply a condition during which a player may perform some action. Some examples include holding a Tool, being seated in a car or standing near a door. Whatever the case may be, it is up to your LocalScripts to call BindAction when the context is entered and UnbindAction when the context is left.

What is an action?

An action is simply some input that can be performed by the player while in that context. Such an action could open/close some menu, trigger a secondary tool action or send a request to the server using RemoteFunction:InvokeServer(). An action is identified by a unique string as the first parameter of both BindAction and UnbindAction. The string can be anything, but it should reflect the action being performed, not the input being used. For example, don't use "KeyH" as an action name - use "CarHorn" instead. It is best to define your actions as a constant at the top of your script since you will use it in at least three different places in your code.

Why bind actions contextually?

It's better to use ContextActionService's BindAction than UserInputService.InputBegan for most cases. For InputBegan, your connected function would have to check if the player is in the context of the action begin performed. In most cases, this is harder than just calling a function when a context is entered/left. For example, if you want to have the H key trigger a car horn sound while the player is sitting in it, the player might type "hello" in chat or otherwise use the H key for something else. It is harder to determine if something else is using the H key (like chat) - the car might honk when the player didn't mean to! If you instead use BindAction and UnbindAction when the player enters/leaves the car, ContextActionService will make sure that H key presses trigger the honk action only when it is the most recently bound action. If something else (like chat) takes control, you won't have to worry about checking that.

Inspecting Bound Actions

To see a list of actions and their bound inputs, you can inspect the "Action Bindings" tab in the Developer Console (F9 while in game). This shows all bindings - including those bound by Roblox CoreScripts and default camera/control scripts too. This is useful for debugging: check if your actions are being bound/unbound at the correct times, or if some other action is stealing input from your actions. For example, if you are attempting to bind WASD, it may be the case that default character movement scripts are binding over those same keys. Similarly, the camera control script can steal right-click input if the script runs after yours.

Keyboardless Input

ContextActionService is especially useful for supporting gamepad and touch input. For gamepad input, you might choose to bind the B button to an action that returns the user to the previous menu when they entire another menu. For touch, on-screen touch buttons can be used in place of key presses: these buttons display only while the action is bound, and the position, text and/or images of these buttons can be configured through this service. They are somewhat limited in the amount of customization provided by this service; it's usually a better idea to make your own on-screen buttons using ImageButton or TextButton.

Code Samples

ContextActionService Tool Reload

1local ContextActionService = game:GetService("ContextActionService")
2
3local ACTION_RELOAD = "Reload"
4
5local tool = script.Parent
6
7local function handleAction(actionName, inputState, _inputObject)
8 if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
9 print("Reloading!")
10 end
11end
12
13tool.Equipped:Connect(function()
14 ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
15end)
16
17tool.Unequipped:Connect(function()
18 ContextActionService:UnbindAction(ACTION_RELOAD)
19end)

Summary

Properties

Events

BoundActionAdded(actionAdded: string, createTouchButton: boolean, functionInfoTable: Dictionary, isCore: boolean): RBXScriptSignal  


BoundActionChanged(actionChanged: string, changeName: string, changeTable: Dictionary): RBXScriptSignal  


BoundActionRemoved(actionRemoved: string, functionInfoTable: Dictionary, isCore: boolean): RBXScriptSignal  



Fires when the current player equips a Tool.


Fires when the current player unequips a Tool.

Methods

BindAction(actionName: string, functionToBind: function, createTouchButton: boolean, inputTypes: Tuple): nil  

Bind user input to an action given an action handling function.

BindActionAtPriority(actionName: string, functionToBind: function, createTouchButton: boolean, priorityLevel: number, inputTypes: Tuple): nil  

Behaves like BindAction but also allows a priority to be assigned to the bound action for overlapping input types (higher before lower).

BindActivate(userInputTypeForActivation: UserInputType, keyCodeForActivation: KeyCode): nil  

Bind a KeyCode with a specific UserInputType to trigger Tool.Activation and ClickDetector events.

BindCoreAction(actionName: string, functionToBind: function, createTouchButton: boolean, inputTypes: Tuple): nil  


BindCoreActionAtPriority(actionName: string, functionToBind: function, createTouchButton: boolean, priorityLevel: number, inputTypes: Tuple): nil  


CallFunction(actionName: string, state: UserInputState, inputObject: Instance): Tuple  


FireActionButtonFoundSignal(actionName: string, actionButton: Instance): nil  



Get a table of information about all bound actions (key is the name passed to BindAction, value is a table from GetBoundActionInfo when called with the key).


Get a table of information about a bound action given its name originally passed to BindAction.

SetDescription(actionName: string, description: string): nil  

Given the name of a bound action with a touch button, sets the description of the action.

SetImage(actionName: string, image: string): nil  

If actionName key contains a bound action, then image is set as the image of the touch button.

SetPosition(actionName: string, position: UDim2): nil  

Given the name of a bound action with a touch button, sets the position of the button within the ContextButtonFrame.

SetTitle(actionName: string, title: string): nil  

Given the name of a bound action with a touch button, sets the text shown on the button.

UnbindAction(actionName: string): nil  

Unbind an action from input given its name.

UnbindActivate(userInputTypeForActivation: UserInputType, keyCodeForActivation: KeyCode): nil  

Unbind a KeyCode with a specific UserInputType from triggering Tool.Activation when bound with ContextActionService:BindActivate().


Removes all functions bound. No actionNames will remain. All touch buttons will be removed.

UnbindCoreAction(actionName: string): nil  


GetButton(actionName: string): Instance  YIELDS

Retrieves a ImageButton of a bound action that had a touch input button created.

Properties

Events

BoundActionAdded

Roblox Script Security

Parameters

actionAdded: string
createTouchButton: boolean
functionInfoTable: Dictionary
isCore: boolean

BoundActionChanged

Roblox Script Security

Parameters

actionChanged: string
changeName: string
changeTable: Dictionary

BoundActionRemoved

Roblox Script Security

Parameters

actionRemoved: string
functionInfoTable: Dictionary
isCore: boolean

GetActionButtonEvent

Roblox Script Security

Parameters

actionName: string

LocalToolEquipped

Fires when the current player equips a Tool.

Parameters

toolEquipped: Instance

LocalToolUnequipped

Fires when the current player unequips a Tool.

Parameters

toolUnequipped: Instance

Methods

BindAction

BindAction will bind an action to user input given an action handling function. Upon a matching input being performed, the action handler function will be called with the arguments listed below. Valid input enum items include those within the following: KeyCode, UserInputType or Enum.PlayerAction . Call this function when a player enters the context in which an action can be performed. When the player leaves the context, call UnbindAction with the same actionName. You can manually call the action handling function of an action by using CallFunction.

The code sample below shows how a Sound can be played while a key (H), game pad button, or touch screen button is pressed.


1local ContextActionService = game:GetService("ContextActionService")
2
3-- A car horn sound
4local honkSound = Instance.new("Sound", workspace)
5honkSound.Looped = true
6honkSound.SoundId = "rbxassetid://9120386436"
7
8local function handleAction(actionName, inputState, inputObject)
9 if actionName == "HonkHorn" then
10 if inputState == Enum.UserInputState.Begin then
11 honkSound:Play()
12 else
13 honkSound:Pause()
14 end
15 end
16end
17
18-- When the player sits in the vehicle:
19ContextActionService:BindAction("HonkHorn", handleAction, true, Enum.KeyCode.H, Enum.KeyCode.ButtonY)
20
21-- When the player gets out:
22ContextActionService:UnbindAction("HonkHorn")
23

Action Handler Parameters

The action handler functions are called with the following parameters:

#TypeDescription
1stringThe same string that was originally passed to BindAction†
2`Enum.UserInputState`The state of the input (Begin, Change, End or Cancel)*
3InputObjectAn object that contains information about the input (varies based on UserInputType)

†This allows one function to handle multiple actions at once, if necessary. *Cancel is sent if some input was in-progress and another action bound over the in-progress input, or if the in-progress bound action was unbound.

Action Bindings Stack

Action bindings behave like a stack: if two actions are bound to the same user input, the most recently bound action handler will be used. If an action handler returns ContextActionResult.Pass, the next most recently bound action handler will be called, and so on until a handler sinks the input (by returning nil or ContextActionResult.Sink). When UnbindAction is called, the action handler is removed from the stack. This stack behavior can be overridden using BindActionAtPriority, where an additional priority parameter after createTouchButton may override the order in which actions are bound (higher before lower).

Touch Buttons

In addition to input types, this function's third parameter controls whether a button is created for TouchEnabled devices. Upon the first touch button's creation, a ScreenGui named "ContextActionGui" is added to the PlayerGui. Inside the ScreenGui is a Frame called "ContextButtonFrame" is added. It is in this frame in which ImageButtons for bound actions are parented; you can use GetButton to retrieve such buttons for customization.

Parameters

actionName: string

A string representing the action being performed (e.g. "HonkHorn" or "OpenDoor").

functionToBind: function

The action-handling function, called with the following parameters when the bound inputs are triggered: string (actionName), Enum.UserInputState and an InputObject.

createTouchButton: boolean

Whether a GUI button should be created for the action on touch input devices.

inputTypes: Tuple

Any number of Enum.KeyCode or Enum.UserInputType representing the inputs to bind to the action.


Returns

Code Samples

General Action Handler

1local ContextActionService = game:GetService("ContextActionService")
2
3local function handleAction(actionName, inputState, inputObj)
4 if inputState == Enum.UserInputState.Begin then
5 print("Handling action: " .. actionName)
6 print(inputObj.UserInputType)
7 end
8
9 -- Since this function does not return anything, this handler will
10 -- "sink" the input and no other action handlers will be called after
11 -- this one.
12end
13
14ContextActionService:BindAction("BoundAction", handleAction, false, Enum.KeyCode.F)
ContextActionService Tool Reload

1local ContextActionService = game:GetService("ContextActionService")
2
3local ACTION_RELOAD = "Reload"
4
5local tool = script.Parent
6
7local function handleAction(actionName, inputState, _inputObject)
8 if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
9 print("Reloading!")
10 end
11end
12
13tool.Equipped:Connect(function()
14 ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
15end)
16
17tool.Unequipped:Connect(function()
18 ContextActionService:UnbindAction(ACTION_RELOAD)
19end)
Stacked Action Handlers

1local ContextActionService = game:GetService("ContextActionService")
2
3-- Define an action handler for FirstAction
4local function actionHandlerOne(actionName, inputState, _inputObj)
5 if inputState == Enum.UserInputState.Begin then
6 print("Action Handler One: " .. actionName)
7 end
8 -- This action handler returns nil, so it is assumed that
9 -- it properly handles the action.
10end
11
12-- Binding the action FirstAction (it's on the bottom of the stack)
13ContextActionService:BindAction("FirstAction", actionHandlerOne, false, Enum.KeyCode.Z, Enum.KeyCode.X, Enum.KeyCode.C)
14
15-- Define an action handler for SecondAction
16local function actionHandlerTwo(actionName, inputState, inputObj)
17 if inputState == Enum.UserInputState.Begin then
18 print("Action Handler Two: " .. actionName)
19 end
20
21 if inputObj.KeyCode == Enum.KeyCode.X then
22 return Enum.ContextActionResult.Pass
23 else
24 -- Returning nil implicitly Sinks inputs
25 return Enum.ContextActionResult.Sink
26 end
27end
28
29-- Binding SecondAction over the first action (since it bound more recently, it is on the top of the stack)
30-- Note that SecondAction uses the same keys as
31ContextActionService:BindAction("SecondAction", actionHandlerTwo, false, Enum.KeyCode.Z, Enum.KeyCode.X)

BindActionAtPriority

BindActionAtPriority behaves like BindAction but also allows a priority to be assigned to the bound action. If multiple actions are bound to the same input, the higher priority function is called regardless of the order in which the actions were bound. In other words, this function overrides the normal "stack" behavior of BindAction.

Parameters

actionName: string

A string representing the action being performed (e.g. "HonkHorn" or "OpenDoor").

functionToBind: function

The action-handling function, called with the following parameters when the bound inputs are triggered: string (actionName), Enum.UserInputState and an InputObject.

createTouchButton: boolean

Whether a GUI button should be created for the action on touch input devices.

priorityLevel: number

The priority level at which the action should be bound (higher considered before lower).

inputTypes: Tuple

Any number of Enum.KeyCode or Enum.UserInputType representing the inputs to bind to the action.


Returns

Code Samples

ContextActionService BindAction Priorities

1local ContextActionService = game:GetService("ContextActionService")
2
3local INPUT_KEY = Enum.KeyCode.Q
4local INPUT_KEY2 = Enum.KeyCode.E
5
6local function handleThrow()
7 print("Throw")
8end
9local function handePunch()
10 print("Punch")
11end
12
13-- Notice how Throw is bound at a higher priority than Punch (2>1)
14-- Therefore, despite the order in which they were bound (Throw then Punch),
15-- handleThrow will be called before handlePunch when INPUT_KEY (Q) is pressed.
16ContextActionService:BindActionAtPriority("Throw", handleThrow, false, 2, INPUT_KEY)
17ContextActionService:BindActionAtPriority("Punch", handePunch, false, 1, INPUT_KEY)
18-- Here, we don't use a priority (BindAction) so order matters.
19-- Since Punch2 is bound after Throw2, it takes priority for INPUT_KEY2 (E).
20ContextActionService:BindAction("Throw2", handleThrow, false, INPUT_KEY2)
21ContextActionService:BindAction("Punch2", handePunch, false, INPUT_KEY2)

BindActivate

Bind an KeyCode that can be used with a UserInputType to activate ClickDetector events and Tool objects. When the given key/button is pressed, it fires the Mouse.Button1Down event on the mouse sent to Tool.Equipped. This in turn fires the Tool.Activated event if Tool.ManualActivationOnly is not set to true. For gamepad input, this function is called by the default control scripts in order to bind the ButtonR2 KeyCode.

Note that the UserInputType specified must be Keyboard or Gamepad1 through Gamepad8 in order to be valid.

Parameters

userInputTypeForActivation: UserInputType

Must be Keyboard or Gamepad1 through Gamepad8.

keyCodeForActivation: KeyCode

The KeyCode (e.g. ButtonX) to bind.

Default Value: "Unknown"

Returns

BindCoreAction

Roblox Script Security

Parameters

actionName: string
functionToBind: function
createTouchButton: boolean
inputTypes: Tuple

Returns

BindCoreActionAtPriority

Roblox Script Security

Parameters

actionName: string
functionToBind: function
createTouchButton: boolean
priorityLevel: number
inputTypes: Tuple

Returns

CallFunction

Roblox Script Security

Parameters

actionName: string
inputObject: Instance

Returns

FireActionButtonFoundSignal

Roblox Script Security

Parameters

actionName: string
actionButton: Instance

Returns

GetAllBoundActionInfo

GetAllBoundActioninfo returns a table which maps all actions' names (those originally passed to BindAction) to a table returned by GetBoundActionInfo when called with the action name itself. Using this function, you can inspect all presently bound actions. This is useful when debugging their priority levels or stack orders.


Returns

GetAllBoundCoreActionInfo

Roblox Script Security

Returns

GetBoundActionInfo

GetBoundActionInfo returns a table with the following keys describing a bound action given its name. To get the same information for all actions at once, use GetAllBoundActionInfo.

NameTypeDescription
stackOrdernumber

Describes the index of the action on the stack (increasing)

priorityLevel*number

Describes the priority level of the action

createTouchButtonbool

Describes whether a touch button should be created on TouchEnabled devices

inputTypestable

The input types passed to BindAction for which this action will trigger

descriptionstring

The description of action set by SetDescription

titlestring

The title of the action set by SetTitle

imagestring

The image of the action's touch button set by SetImage

*Priority level will still be included even if BindActionAtPriority wasn't used - by default it will be 2000. †Indicates that this field will be nil if the associated method was not called for the given action.

Parameters

actionName: string

Returns

GetBoundCoreActionInfo

Roblox Script Security

Parameters

actionName: string

Returns

GetCurrentLocalToolIcon

GetCurrentLocalToolIcon will return the BackpackItem.TextureId of a Tool currently equipped by the Player, or nil if there is no such Tool or if the player lacks a Character.


Returns

A content string from the Tool's TextureId, or nil if one could not be found.

SetDescription

SetDescription will set the description of an action bound by BindAction. In a list of available actions, this would be text that describes the given action.

Although the name may suggest that this method is related to the family of functions that customize a touch button for actions that create them (SetTitle, SetImage and SetPosition), this method does not affect such a button. This method merely sets a text description of an action, and nothing more.

Parameters

actionName: string

The name of the action originally passed to BindAction.

description: string

A text description of the action, such as "Honk the car's horn" or "Open the inventory".


Returns

Code Samples

ContextActionService Touch Button

1local ContextActionService = game:GetService("ContextActionService")
2
3local ACTION_INSPECT = "Inspect"
4local INPUT_INSPECT = Enum.KeyCode.E
5local IMAGE_INSPECT = "rbxassetid://1826746856" -- Image of a speech bubble with ? in it
6
7local function handleAction(actionName, inputState, _inputObject)
8 if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
9 print("Inspecting")
10 end
11end
12
13-- For touch devices, a button is created on-screen automatically via the 3rd parameter
14ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
15-- We can use these functions to customize the button:
16ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
17ContextActionService:SetTitle(ACTION_INSPECT, "Look")
18ContextActionService:SetDescription(ACTION_INSPECT, "Inspect something.")
19ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
20-- We can manipulate the button directly using ContextActionService:GetButton
21local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
22if imgButton then -- Remember: non-touch devices won't return anything!
23 imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Tint the ImageButton green
24end

SetImage

SetPosition will set the text shown on a touch button created by BindAction. Specifically, this sets the ImageLabel.Image property of the ImageLabel within the ImageButton that would be returned by GetButton. If no such bound action exists (e.g. nothing is returned by GetButton), this function does nothing and throws no error.

This function is part of a family of methods that customize the touch button of an action. Others in this family include SetPosition and SetTitle.

Parameters

actionName: string

The name of the action originally passed to BindAction.

image: string

The value to which the Image property should be set.


Returns

Code Samples

ContextActionService Touch Button

1local ContextActionService = game:GetService("ContextActionService")
2
3local ACTION_INSPECT = "Inspect"
4local INPUT_INSPECT = Enum.KeyCode.E
5local IMAGE_INSPECT = "rbxassetid://1826746856" -- Image of a speech bubble with ? in it
6
7local function handleAction(actionName, inputState, _inputObject)
8 if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
9 print("Inspecting")
10 end
11end
12
13-- For touch devices, a button is created on-screen automatically via the 3rd parameter
14ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
15-- We can use these functions to customize the button:
16ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
17ContextActionService:SetTitle(ACTION_INSPECT, "Look")
18ContextActionService:SetDescription(ACTION_INSPECT, "Inspect something.")
19ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
20-- We can manipulate the button directly using ContextActionService:GetButton
21local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
22if imgButton then -- Remember: non-touch devices won't return anything!
23 imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Tint the ImageButton green
24end

SetPosition

SetPosition sets the position of a touch button created by BindAction. Specifically, this sets the GuiObject.Position property of the ImageButton that would be returned by GetButton. If no such bound action exists (e.g. nothing is returned by GetButton), this function does nothing and throws no error.

This function is part of a family of methods that customize the touch button of an action. Others in this family include SetImage and SetTitle.

Parameters

actionName: string

The name of the action originally passed to BindAction.

position: UDim2

The position within the ContextButtonFrame.


Returns

Code Samples

ContextActionService Touch Button

1local ContextActionService = game:GetService("ContextActionService")
2
3local ACTION_INSPECT = "Inspect"
4local INPUT_INSPECT = Enum.KeyCode.E
5local IMAGE_INSPECT = "rbxassetid://1826746856" -- Image of a speech bubble with ? in it
6
7local function handleAction(actionName, inputState, _inputObject)
8 if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
9 print("Inspecting")
10 end
11end
12
13-- For touch devices, a button is created on-screen automatically via the 3rd parameter
14ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
15-- We can use these functions to customize the button:
16ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
17ContextActionService:SetTitle(ACTION_INSPECT, "Look")
18ContextActionService:SetDescription(ACTION_INSPECT, "Inspect something.")
19ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
20-- We can manipulate the button directly using ContextActionService:GetButton
21local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
22if imgButton then -- Remember: non-touch devices won't return anything!
23 imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Tint the ImageButton green
24end

SetTitle

SetTitle will set the text shown on a touch button created by BindAction. Specifically, this sets the TextLabel.Text property of a TextLabel within the ImageButton that would be returned by GetButton. If no such bound action exists (e.g. nothing is returned by GetButton), this function does nothing and throws no error.

This function is part of a family of methods that customize the touch button of an action. Others in this family include SetImage and SetPosition.

Parameters

actionName: string

The name of the action originally passed to BindAction.

title: string

The text to display on the button.


Returns

Code Samples

ContextActionService Touch Button

1local ContextActionService = game:GetService("ContextActionService")
2
3local ACTION_INSPECT = "Inspect"
4local INPUT_INSPECT = Enum.KeyCode.E
5local IMAGE_INSPECT = "rbxassetid://1826746856" -- Image of a speech bubble with ? in it
6
7local function handleAction(actionName, inputState, _inputObject)
8 if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
9 print("Inspecting")
10 end
11end
12
13-- For touch devices, a button is created on-screen automatically via the 3rd parameter
14ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
15-- We can use these functions to customize the button:
16ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
17ContextActionService:SetTitle(ACTION_INSPECT, "Look")
18ContextActionService:SetDescription(ACTION_INSPECT, "Inspect something.")
19ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
20-- We can manipulate the button directly using ContextActionService:GetButton
21local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
22if imgButton then -- Remember: non-touch devices won't return anything!
23 imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Tint the ImageButton green
24end

UnbindAction

UnbindAction will unbind an action by name from user inputs so that the action handler function will no longer be called. Call this function when the context for some action is no longer applicable, such as closing a user interface, exiting a car or unequipping a Tool. See BindAction for more information on how bound actions operate.

This function will not throw an error if there is no such action bound with the given string. Using GetAllBoundActionInfo or the Developer Console's "Action Bindings" tab, you can find out what actions are presently bound.

Parameters

actionName: string

Returns

Code Samples

ContextActionService Tool Reload

1local ContextActionService = game:GetService("ContextActionService")
2
3local ACTION_RELOAD = "Reload"
4
5local tool = script.Parent
6
7local function handleAction(actionName, inputState, _inputObject)
8 if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
9 print("Reloading!")
10 end
11end
12
13tool.Equipped:Connect(function()
14 ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
15end)
16
17tool.Unequipped:Connect(function()
18 ContextActionService:UnbindAction(ACTION_RELOAD)
19end)

UnbindActivate

UnbindActivate unbinds an KeyCode used with an UserInputType for activating a Tool (or a HopperBin) using BindActivate. This function essentially undoes the action performed by that function.

Parameters

userInputTypeForActivation: UserInputType

The same UserInputType originally sent to BindActivate.

keyCodeForActivation: KeyCode

The same KeyCode originally sent to BindActivate.

Default Value: "Unknown"

Returns

UnbindAllActions

Removes all functions bound. No actionNames will remain. All touch buttons will be removed. If a button was manipulated manually there is no guarantee it will be cleaned up.


Returns

UnbindCoreAction

Roblox Script Security

Parameters

actionName: string

Returns

GetButton

Yields

GetButton returns the ImageButton created by BindAction if its third parameter was true and the device is TouchEnabled. The only parameter to this function must match exactly the name of the action originally sent to BindAction.

If no such action was bound or if a button was not created, this function returns nil.

Parameters

actionName: string

The name of the action originally passed to BindAction.


Returns

An ImageButton created by BindAction.