ContextActionService
ContextActionService : Instance
Overview
The ContextActionService class is a service that allows developers to bind user inputs to specific actions under certain conditions or contexts. It provides a way to map various input types to in-game actions, making it easier to create responsive and intuitive controls for players across multiple devices. This service is particularly useful for managing contextual input, such as enabling specific actions only when a tool is equipped or a player is near an object
Description
The ContextActionService simplifies input handling by allowing developers to define actions and associate them with user inputs. These actions can be dynamically enabled or disabled based on the player's current context, such as proximity to an object or interaction with a specific tool.
Properties
Methods
BindAction
Defines an action and binds the function to handle the action.
Parameters
string
ActionName
Value
FunctionToBind
bool
bCreateTouchButton
Tuple
InputType
Return
void
Code Samples
UnbindAction
Remove and unbind action.
Parameters
string
ActionName
Return
void
Code Samples
GetAllBoundActionInfo
Gets all action information bound to the ContextActionService.
Parameters
Return
Value
Code Samples
GetBoundActionInfo
The GetBoundActionInfo method retrieves action information based on the provided action name and returns it.
Parameters
string
ActionName
Return
Value
Code Samples
SetDescription
Given the name of a bound action with a touch button, sets the description of the action.
Parameters
string
ActionName
string
InDescription
Return
void
Code Samples
SetImage
If actionName key contains a bound action, then image is set as the image of the touch button.
Parameters
string
ActionName
string
ImageId
Return
void
Code Samples
SetPosition
Given the name of a bound action with a touch button, sets the position of the button within the ContextButtonFrame.
Parameters
string
ActionName
UDim2
InPosition
Return
void
Code Samples
SetTitle
Given the name of a bound action with a touch button, sets the text shown on the button.
Parameters
string
ActionName
string
InTitle
Return
void
Code Samples
GetButton
Retrieves a ImageButton of a bound action that had a touch input button created.
Parameters
string
ActionName
Return
Value
Code Samples
Events
LocalToolEquipped
This event fires when a tool is equipped locally. Typically used to handle or initialize any functionality or UI specific to the equipped tool. Can be leveraged to manage tool-specific actions or properties.
Parameters
Code Samples
LocalToolUnequipped
This event fires when a tool is unequipped locally. It is typically used to clean up or reset functionality or UI that was specific to the equipped tool. Useful for managing resources or reverting actions tied to the tool.