Mobile Buttons & Context Input

ContextActionService (usually shortened to CAS) lets you create an action such as:

Jump, Attack, Dash, Sprint, Interact, Reload

NOTE: only a local sided feature (goes in a local script)


1. Why Use It?

Without ContextActionService, you might do something like:

-- Keyboard
UserInputService.InputBegan

-- Controller
UserInputService.InputBegan

-- Mobile
UserInputService.TouchStarted

With ContextActionService, you can say:

"These inputs all mean JUMP."

one action to handle all the input instead of creating multiple !


Example

In a local script

local contextInput = game:GetService("ContextActionService")
local tool = script.Parent

local function PressE(actionName, inputState) //create the function
	
	if inputState == Enum.UserInputState.Begin then
		print("Player has pressed E")
		
	end
	
end

contextInput:BindAction("PressE", PressE, true, Enum.KeyCode.E)

The general structure is:

ContextActionService:BindAction(
	actionName, //call it whatever you want
	function,
	createTouchButton,
	inputs...
)


2.InputState

Enum.UserInputState.Begin
Enum.UserInputState.Change
Enum.UserInputState.End

Begin = pressed

Change = changing/held behavior

End = released