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

Gamepad Detection System not working properly - can someone help?

Asked by 7 years ago

Hello, everyone.

I have a game that will be played by both people on Xbox One and people on PC.

The only problem is that while it works if you connect or disconnect a controller while the game is running, and the buttons appear or disappear, respectfully, I can't seem to make it detected an absent gamepad or one that's plugged in currently, making the buttons either disappear or reappear respectfully.

I'd appreciate some help with this. Any help is much appreciated.






while true do wait(0) if game:GetService("UserInputService").GamepadEnabled then game:GetService("UserInputService").GamepadConnected:connect(function(gamepad) script.Parent.Visible = true --Make the gamepad buttons visible game:GetService("UserInputService").GamepadDisconnected:connect(function(gamepad) script.Parent.Visible = false --Make the gamepad buttons invisible end) end) end end

1 answer

Log in to vote
0
Answered by 7 years ago

This should work for you, much more efficient than a loop too!

I've encountered trouble trying to detect a gamepad before it can be detected, so the character + 2 second wait are just there because I'm paranoid.

repeat wait() until game.Players.LocalPlayer.Character
wait(2)
if game:GetService("UserInputService").GamepadEnabled then
    script.Parent.Visible = true
end

game:GetService("UserInputService").GamepadConnected:connect(function(gamepad)
    script.Parent.Visible = true
end)
game:GetService("UserInputService").GamepadDisconnected:connect(function(gamepad)
    script.Parent.Visible = false
end)
0
Thank you! This works perfectly. c: TheRings0fSaturn 28 — 7y
Ad

Answer this question