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

How do I get a player's Gamepad if gamepadEnabled is true?

Asked by 4 years ago
local uis = game:GetService("UserInputService")
local hasGamepad = uis.GamepadEnabled
if hasGamepad then 

else
    uis.GamepadConnected:Connect(function(gamepad)
        local getGamepad = uis:GetGamepadConnected(gamepad)
        if getGamepad then 
            print("True!")
            if gamepad == Enum.UserInputType.Gamepad1 then 
                print("Gamepad1 !")
            end
        end
    end)
end

In this code, I try getting a player's gamepadEnabled value. If it's true (meaning a gamepad is connected), I wanna get their gamepad and print out "Gamepad1 !" if that gamepad is equal to "Enum.UserInputType.Gamepad1". If gamepadEnabled is false, it waits for a gamepad to connect. If one connects, it runs lines 7-13. How do I get the player's gamepad and its UserInputType if they already have a gamepad connected?

1 answer

Log in to vote
1
Answered by
Prestory 1395 Moderation Voter
4 years ago

Well you should do the checking for an already plugged in game pad separate in another script here is an example of how you could do it insert a script into ServerScriptService and insert the code i have provided for you below into the script.

local UserInputService = game:GetService('UserInputService')
local GamePadEnabled = UserInputService.GamepadEnabled

local function SearchForPluggedController ()
if GamePadEnabled then
if UserInputService:GetGamepadConnected(Enum.UserInputType.Gamepad1) then
print("Gamepad1  !")
end
end 
end

game.Players.PlayerAdded:Connect(function(player)
    SearchForPluggedController()
end)

(Not tested might not be 100% accurate)

Ad

Answer this question