I want to make the InputBegan/InputEnded event work again after switching from Gamepad → Keyboard → Gamepad, just like other games.
But, heres the thing; after switching, the InputBegan event doesn’t detect the Gamepad anymore, but it can detect the Keyboard.
Why is that? And how can I fix it?
And yes, I tested it.
game:GetService('UserInputService').InputBegan:Connect(function(input)
print('Input Detected')
if input.KeyCode == (Enum.KeyCode.Space or Enum.KeyCode.ButtonA) then print('Hey cool') end
end)
I probably didnt explain this right, but ButtonA doesn’t seem to be working at all. But Space does. It detects input, but sometimes doesnt. Doing further tests.
not what youre asking for but use contextactionservice, if not then i dont have any idea why its not working, you could try making a different event for the gamepad
thats great because context action service is far better imo
but to do what youre looking for you would do something like this
local ContextActionService = game:GetService("ContextActionService")
local function randomName(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
print("hi guys")
end
end
ContextActionService:BindAction("jump", randomName, false, Enum.KeyCode.Space, Enum.KeyCode.ButtonA )
heres an explanation when you bind
ContextActionService:BindAction(
"jump", -- define a name
randomName, -- the function
false, -- set to true if youd like to create a touch button
-- now set keycodes
Enum.KeyCode.Space,
Enum.KeyCode.ButtonA
)
of course if you dont need to listen for it then you can simply unbind using :Unbind(actioname)
I could reproduce the issue with your code. I used an Xbox controller and my laptop keyboard. Reformatting the code, however, fixed the problem.
*ignore the terrible stick drift
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input)
print("Input Detected")
if input.KeyCode == Enum.KeyCode.Space or input.KeyCode == Enum.KeyCode.ButtonA then
print("Hey cool")
print(input.KeyCode)
end
end)
The issue stemmed from how you used or in the code, which I believe starts a new check and can’t be used for conditional statements like you tried to use them. You’d have to declare input.Keycode == again for that or check.