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