Gamepad ButtonA not working

I’m testing using an Xbox controller since I don’t have a PlayStation controller unfortunately, but for me the code is working correctly

Edit: @tannnxr Here’s the one that uses UserInputService edited to include the path to your RemoteEvents:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

local events = ReplicatedStorage:WaitForChild("Events")
local reDash = events:WaitForChild("Dash")
local reSprint = events:WaitForChild("Sprint")

local function movementHandler(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(movementHandler)

And the same for ContextActionService:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")

local events = ReplicatedStorage:WaitForChild("Events")
local reDash = events:WaitForChild("Dash")
local reSprint = events:WaitForChild("Sprint")

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)
1 Like

Okay update:

It works if I am moving with the W key and then hit the X key on my controller, idk why it does that but super strange nontheless

EDIT: Both the UIS and ContextAction solutions only work while using keyboard AND controller together, so I have to hit a movement key on my keyboard and then X on my controller then it works, but not if im using the joystick to move.

This shouldn’t be happening and it’s not happening to me when I test the code exactly as I gave it to you

Out of curiosity, type this in your command bar while your gamepad is connected and reply with the result:

for _, keyCode in game.UserInputService:GetSupportedGamepadKeyCodes(Enum.UserInputType.Gamepad1) do print(keyCode) end
1 Like

I’m also noticing you wrote this in the code you gave me:

Why are you retrieving the services from a module? It might be causing the issues
How is your code written like now?

1 Like

I have the code exactly as you’ve given it to me now

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")

local events = ReplicatedStorage:WaitForChild("Events")
local reDash = events:WaitForChild("Dash")
local reSprint = events:WaitForChild("Sprint")

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)

retrieving from a module wasn’t the issue as it has always worked for literally EVERY other keycode i used, it’s like specifically not working for ButtonA (standard “jump” button), it works for ButtonX, ButtonB, everything else just not ButtonA for some reason.

I’m not lying when I’m saying I tested the code to make sure it works before I sent it to you, but as I mentioned I used an Xbox controller to do so

I think this might be some weird compatibility issue since PlayStation support in Roblox is a relatively recent addition, unfortunately at this point I’m unsure as to how I can help you solve this problem

1 Like

That’s alright, i’ll mark your original code as the solution and just change the keybind to like my circle button since that is generally the standard “dodge” button in most games. Thanks for all your help man.

1 Like

I got some important news: I managed to replicate this problem myself after some heavy testing since I was curious as to why this is happening. Using any keyCode other than ButtonA works perfectly as expected but the default player control script seems to override the keyCode. The only guaranteed solution I found is to disable the default player controls script by placing a LocalScript named “ControlScript” inside of StarterPlayerScripts, but obviously this isn’t ideal. I even tried using ContextActionService:BindActionAtPriority and set the priotity to math.huge but the issue still occured. I suggest you report this to Roblox because this does seem to be a bug you’ve discovered

It’s good that you got that solution. I wasn’t sure what was going on. Besides, the OP can unbind the default action like this:

ContextActionService:UnbindAction("jumpAction")

The OP needs to put it somewhere before the bind actions.

1 Like

True, but it’s at a cost of players being unable to jump within the game unfortunately (although it’s quite easy to make a custom jump bind that uses a different KeyCode)

If jumping isn’t necessary in the game, then that would be a good solution to the problem which would allow OP to use ButtonA as they desire

Well thankfully like you mentioned, the game does not require jumping and I actually disabled it by setting their jump power to zero. I will do Mael’s solution and see if that works and then update everyone.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.