Gamepad ButtonA not working

I am trying to connect to the ContextActionService to make my game playable with KBM and Controller however I am having an issue with my dash ability not working specifically with the ButtonA keycode for controller. It works with literally any other key I tried on my controller.

I am using an official PS4 controller for testing.

I saw another post about the UserInputService however I am not having that issue, I don’t think. Here is my code:

--- Run Context: Client
--- Services is already defined.
Services.ContextAction:BindAction("movement", movementHandler, false, 
	Enum.KeyCode.Space,
	Enum.KeyCode.LeftShift,
	Enum.KeyCode.ButtonA)
--- Run Context: Client

function movementHandler(actionName: string, inputState: Enum.UserInputState, inputObject)
	
	if inputState == Enum.UserInputState.End then
		if inputObject.KeyCode == Enum.KeyCode.Space or inputObject.KeyCode == Enum.KeyCode.ButtonA then
			reDash:FireServer()
		elseif inputObject.KeyCode == Enum.KeyCode.LeftShift then
			reSprint:FireServer()
		end
	end
end
--- Run Context: Server
function dashHandler(player: Player)
	print("Dash Server")
	local bvPushingForce = Instance.new("BodyVelocity")
	
	local mdCharacter = player.Character
	local humHumanoid: Humanoid = mdCharacter:FindFirstChild("Humanoid")
	
	local bphumanoidRootPart: BasePart = mdCharacter:FindFirstChild("HumanoidRootPart")
	
	local animator = humHumanoid:FindFirstChildOfClass("Animator")
	if animator then
		local dashAnimation = Instance.new("Animation")
		dashAnimation.AnimationId = "rbxassetid://15930101859"
		local animationTrack = animator:LoadAnimation(dashAnimation)
		
		if animationTrack then
			animationTrack:Play()
		end
	end
	
	local vecMovementDirection = bphumanoidRootPart.CFrame.LookVector
	
	bvPushingForce.Velocity = vecMovementDirection * 150 + Vector3.new(0, 5, 0)
	bvPushingForce.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bvPushingForce.Parent =  bphumanoidRootPart
	
	wait(0.5)
	
	bvPushingForce:Destroy()
end

again this works with literally any other keycode other than ButtonA, it doesn’t even print Dash Server, which leads me to believe the event isn’t being fired for some reason?

1 Like

How many ContextActionService bindings do you have? There’s a hard limit of 7 I believe. Anything beyond that and ContextActionService will not fire.

So for this it does fire when I replace the ButtonA with like ButtonX for example. ButtonX will fire it but ButtonA wont for some reason.

EDIT: I tried this on two different controllers and it didn’t work for either one of them, so I know it’s not a controller issue

You might have to unbind button A. Button A is set to the jump action by default.

Xbox One App: How to Play a Roblox Experience

EDIT:
If push comes to shove, I have a ContextActionService replacement that I wrote in the Community Resources forum. The setup is a little different, but the actual function calls are the same, so you shouldn’t need to perform any changes to the actual handlers.

This doesn’t help because the Space bar is also bound to jump however I can still use the dash ability. I have also disabled jumping entirely for players. I don’t know why specifically ButtonA isn’t working.

Put this in a local script on a new baseplate and try it:

local userInputService = game:GetService("UserInputService")

userInputService.InputBegan:Connect(function(inputObject, processed)
	if inputObject.KeyCode == Enum.KeyCode.ButtonA then
		print("Button A pressed.")
	end
end)

userInputService.InputEnded:Connect(function(inputObject, processed)
	if inputObject.KeyCode == Enum.KeyCode.ButtonA then
		print("Button A released.")
	end
end)

If it’s printing, then the problem is something to do with your scripts. If it’s not printing, then there’s some issue outside of Roblox, or it could be Roblox itself.

If thats the case then why not just use

UIS.JumpRequest

It detects if ButtonA or spacebar is pressed. You can filter out for mobile as well.

Strange that this works but not for ContextActionService, I really don’t know what the issue could be.

How many Context Action Service bindings do you have?

As I said, there is a hard limit and anything past that will not function.

Right now, only 4, so I do not have the hard cap

I can’t find your module, can you directly link it for me?

Since you’re checking the input’s KeyCode inside of your movementHandler function anyways, I’d recommend you use UserInputService instead of ContextActionService by doing this:

local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input, gameProcessedEvent)
	if gameProcessedEvent then return end

	if input.KeyCode == Enum.KeyCode.Space or input.KeyCode == Enum.KeyCode.ButtonA then
		reDash:FireServer()
	elseif input.KeyCode == Enum.KeyCode.LeftShift then
		reSprint:FireServer()
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

Alright i’ll probably do that, I was just using the contextaction for multiple controls

1 Like

When using ContextActionService, you’re meant to check either the InputState (you always need to check the InputState, actually) or the action’s name, I’ll write an example that uses ContextActionService if you prefer

Edit: @tannnxr I tested this example and it should work to achieve what you want:

local ContextActionService = game:GetService("ContextActionService")

local function movementHandler(actionName, inputState)
	if inputState == Enum.UserInputState.Begin then
		if actionName == "dash" then
			reDash:FireServer()
		elseif actionName == "sprint" then
			reSprint:FireServer()
		end
	end
end

ContextActionService:BindAction("dash", movementHandler, false, Enum.KeyCode.Space, Enum.KeyCode.ButtonA)
ContextActionService:BindAction("sprint", movementHandler, false, Enum.KeyCode.LeftShift)

Here’s the link to the post. I was posted above. Not sure why you can’t find it.

1 Like

Okay so I wrote some code for UserInputService but now it’s still not working, did I do something wrong here?

Context: Space works, ButtonA doesnt.


print("InputManager Loaded")

local Services = require(script:WaitForChild("Services"))

local serReplicatedStorage = game:GetService("ReplicatedStorage")
local dirEvents = serReplicatedStorage:WaitForChild("Events")
local reDash = dirEvents:WaitForChild("Dash")
local reSprint = dirEvents:WaitForChild("Sprint")


function movementHandler(inputObject, gameProcessed: boolean)
	if gameProcessed then return end
	if inputObject.UserInputType == Enum.UserInputType.Keyboard or inputObject.UserInputType == Enum.UserInputType.Gamepad1 then
		if inputObject.KeyCode == Enum.KeyCode.Space or inputObject.KeyCode == Enum.KeyCode.ButtonA then
			reDash:FireServer()
		end
	end
end


Services.UserInput.InputBegan:Connect(movementHandler)

These checks aren’t really necessary to achieve the correct result:

Edit: @tannnxr You also didn’t include the reSprint event like in my example:

1 Like

What do you mean? Can you elaborate on this?

For it to work correctly, you’ll need to copy my example exactly essentially

1 Like

Copied the code exactly, still does not work with the ButtonA, but works with the space bar