Gamepad not detected? Why? (Using both Gamepad and Keyboard)

Well, heres an explanation.

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)
3 Likes

Edited, i dont know how this even happened, from working to not working.

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.

1 Like

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

1 Like

Thanks, trying now
easdasdasdsad

1 Like

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)

2 Likes

Thanks, but ButtonX doesnt seem to be working. But other actions do. Why is that?

1 Like

lemme see the code

1 Like
function Printing()
	print('Good job')
end

game:GetService('ContextActionService'):BindAction('Yo', Printing, true, Enum.KeyCode.ButtonX)

I tried with ButtonY and it worked

1 Like

W, but add

if inputState == Enum.UserInputState.Begin then
end

inside your function because if you don’t itll print Good job both when you press and release

1 Like

Thanks, but you still got any idea about ButtonX? Or do I have to use jumprequest instead?

1 Like

I mean does ButtonX not work at all? It seems weird.

1 Like

for your thing about the button x

I haven’t played on Xbox or on a console in a really long time, but button X may already be binded to a function which is why buttonX doesn’t work

you could try using :BindActionAtPriority and set the priority higher, but i never had to use this before so im not sure if it will work

1 Like

doesn’t work, thats probably correct that its binded to a function. Tried math.huge. But i’ll mark it as solution though.

1 Like

oh well sorry i couldnt fix it, good luck though

2 Likes

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.

ty so much, you saved me a lot of time of trying to move it to context action service lol

1 Like

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