Script not detecting gamepad input

So I’m trying to bind an action to a button on a gamepad but it doesn’t seem to work. My colleague who has a controller to test says it doesn’t work. I use this article to help me program it. They also use DS4Windows and a PS4 controller so maybe that’s causing the issue? I’m not sure

1 Like

Where’s your script?

No one can help you if we don’t know the code you wrote. Plus, with that, we can’t tell if it’s a problem with a script or your colleague’s computer.

We need to see the script and the output first. We have no idea how to help unless you show us.

Oh yeah sorry about that here it is. Also there is no errors in the output:

game:GetService("UserInputService").InputBegan:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.ButtonL2 then --When the gamepad left trigger is pressed
			sprintCharacter(true) --Sprint
		end
	end
end)
game:GetService("UserInputService").InputEnded:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.ButtonL2 then --When the gamepad's left trigger is released
			sprintCharacter(false) --Stop sprinting
		end
	end
end)
1 Like

Have you tried debugging? Like using print? That could help you if your function is actually running.

Yep and the print statements aren’t being called

Can you show me where you placed the print statements?

I placed them right under the InputBegan and InputEnded lines

What kind of script are you using? If you’re using a server script, that might be the problem as I believe that UserInputService can only be used on the client (prove me if I’m wrong).

Nope I’m using a local script inside starter player scripts

Try using ContextActionService instead and binding print functions to your gamepad inputs if it’s any different

I just tried that and still it does not work

Try placing a print outside all of your functions to decide if your script is actually running.

Tested that and the script is being run