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

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

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

✓ Accepted answer

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)

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