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)
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.
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
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.
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
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.