Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Run code when a Gamepad Button is pressed?

Hello scriptinghelpers. I just would like to understand how to make my script recognize and run a block of code when a Gamepad button is pressed. I have already tried using the UserInputService through the 'InputBegan' event, but I knew that something was off, or maybe I was using it wrong.

Specifically, I am trying to make a script that detects when a UserInputType Enum (Gamepad8) is pressed and then it will run some code. Thank you!

2 answers

✓ Accepted answer

incapaz is correct, but there is another way, like if a player is playing on Xbox or PS4. Another version of incapaz's code:

if game:GetService("UserInputService").GamepadEnabled then
	-- Some example lines
	input = game:GetService("UserInputService").UserInputType
	if input.Thumbstick1 then
		print("Player has pressed down a Thumbstick")
	elseif input.ButtonA then
		print("Player has pressed A")
	end
end

There are quite a few KeyCode values for the Gamepad, and you can look at them here.

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.