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

Gui only visible to xbox users not working correctly?

Asked by 5 years ago

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

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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.

0
Where would I put these "GetGamepadConnected(UserInputType gamepadNum)" or "GetConnectedGamepads()"? TheMaster9245 41 — 5y
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. chomboghai 2044 — 5y
0
I figured it out, thank you! TheMaster9245 41 — 5y
Ad

Answer this question