Gamepad ButtonA not working

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

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