Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Run code when a Gamepad Button is pressed?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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.

0
Thank you! EngineerOfMLG 9 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Enum.KeyCode.ButtonX

Answer this question