ContextAction does not bind to the A button on gamepad

Reproduction Steps
Paste this code into a localscript and press the A button on a gamepad.

game:GetService("ContextActionService"):BindAction("StartGame", function() print("A Button Pressed") end, false, Enum.KeyCode.ButtonA)

Expected Behavior
I expected it to override the character jump and print out “A Button Pressed”

Actual Behavior
The player is still able to jump and “A Button Pressed” is never printed

Workaround
Continue to use an outdated script created by Roblox called ControlScript

Issue Area: Engine
Issue Type: Other
Impact: Very High
Frequency: Constantly
Date First Experienced: 2021-11-20 00:11:00 (-06:00)
Date Last Experienced: 2021-11-20 00:11:00 (-06:00)

3 Likes

You can fix that by setting StarterPlayer.DevComputerMovementMode to “Scriptable”.

1 Like

That did work however the player is unable to move

2 Likes

Pretty sure this is a duplicate of this : Player movement corescripts should not sink input to default keys/buttons

1 Like

I was able to find a workaround.

local connection
connection = game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.ButtonA then
		connection:Disconnect()
		game:GetService("ContextActionService"):BindAction("StartGame", function() print("A Button Pressed") end, false, Enum.KeyCode.ButtonA)
	end
end)
2 Likes

Turns out that if the BindAction is called before any inputs are made on the gamepad, then the binded action will fail every time.

1 Like

You can use ContextActionService::BindActionAtPriority with a higher value than the default ContextActionPriority, and sink the input.

4 Likes

This is a much better workaround, thank you

2 Likes

Please follow this topic for more updates on this issue: Player movement corescripts should not sink input to default keys/buttons

2 Likes