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

Gui only visible to xbox users not working correctly?

the localscript checks if there is a controller in use or something but, when I have my controller already plugged in, it doesn't appear, but when I unplug and plug it back in, it's visible, I don't understand...

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local UIS = game:GetService"UserInputService"

UIS.GamepadEnabled:Connect(function()
	print("gamepad detected")
	script.Parent.YButton.Visible = true
	script.Parent.HoldLabel.Visible = true
end)

1 answer

✓ Accepted answer

The GamepadEnabled event only fires when a user plugs in a gamepad.

This means that if the player already had one plugged in, it would not fire, since he did not just plug it in. However, you can get already connected gamepads by using other UserInputService functions such as

GetGamepadConnected(UserInputType gamepadNum) which returns true or false if the inputted gamepad is connected

GetConnectedGamepads() which returns all the connected game pads.

Hope this helps.

3 comments

0

Where would I put these "GetGamepadConnected(UserInputType gamepadNum)" or "GetConnectedGamepads()"?

0

One way you could do it is create a function enableGamepadUI() that sets the YButton and HoldLabel to visible, and connect that function to the GamepadEnabled event. Then, use the function to check if the gamepad is already connected, and if it is, then call the enableGamepadUI function created earlier.

0

I figured it out, thank you!

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