I have a SurfaceGUI (parented in PlayerGUI and Adorneed to a part) and a LocalScript in PlayerScripts that creates a click event for each of the buttons in the SurfaceGUI
I do this by looping through each of the buttons via collection service as seen here:
print("-----------")
for _, donoButton in COLL:GetTagged("Dono-Btn") do
print("Creating click event for " .. donoButton.Name)
-- When a dono button is clicked
GUI.Connections[donoButton.Name.."Dono"] = donoButton.Activated:Connect(function()
print("Clicked " .. donoButton.Name)
if (donoButton.Name == "AddBtn") then
-- Just updates a textLabel, doesn't create any new function
elseif (donoButton.Name == "SubBtn") then
-- Just updates a textLabel, doesn't create any new function
elseif (donoButton.Name == "SupportButton") then
-- Prompts player to purchase DevProduct, does nothing else
end
end)
end
This works as expected and creates 3 different click events for each of the 3 buttons in the SurfaceGUI as seen here:

However when I click the button named “AddBtn” once, it prints twice:
![]()
Even though the button works as expected and as if it were only clicked once, the button suddenly fires 100 times (with problematic results) when I switch to using a controller (still in Studio on my PC). So I think the root of the problem starts with the button firing twice
The code shown above is part of a larger function that sets up click events for buttons throughout the game and have an almost exact copy of the code shown above elsewhere, but for a different menu, in the same function that only fires buttons once. This other menu is a child of a ScreenGUI, while my problem is with a SurfaceGUI, so I wonder if that has something to do with it?
A skeleton of this function looks like this:
-- Loads GUI
function GUI.LoadGUI()
-- Cleans up events every time function is called
for _, event in GUI.Connections do
if (event) then
event:Disconnect()
event = nil
end
end
-- I create variables for GUI throughout the game here, got rid of it for readablity
-- That "almost the same" code that actually works that I was talking about
for i, button in COLL:GetTagged("MainMenu-Button") do
-- When a main menu button is clicked
GUI.Connections[button.Name] = button.Activated:Connect(function()
if (button.Name == "PlayButton") then
-- Starts my game
elseif (button.Name == "SupportButton") then
-- Opens menu
elseif (button.Name == "SocialsButton") then
-- Opens menu
end
end)
-- I have hover events here to do a little animation when player hovers over buttons
end
-- Problematic code I showed above
print("-----------")
for _, donoButton in COLL:GetTagged("Dono-Btn") do
print("Creating click event for " .. donoButton.Name)
-- When a dono button is clicked
GUI.Connections[donoButton.Name.."Dono"] = donoButton.Activated:Connect(function()
print("Clicked " .. donoButton.Name)
if (donoButton.Name == "AddBtn") then
-- Just updates a textLabel, doesn't create any new function
elseif (donoButton.Name == "SubBtn") then
-- Just updates a textLabel, doesn't create any new function
elseif (donoButton.Name == "SupportButton") then
-- Prompts player to purchase DevProduct, does nothing else
end
end)
-- I have hover events here to do a little animation when player hovers over buttons
end
-- Changes look of game based on what menu player is on
if (GUI.STAGE == 0) then -- When on main menu
elseif (GUI.STAGE == 2) then
elseif (GUI.STAGE == 3) then
end
end
This is part of a massive system that makes my game work, but I’ll save you the pain of figuring out how my entire game is structured and just want to know if anyone has any clue to what is happening because as far as I am aware, my code is working fine. So I wonder if it is setting/property I have set incorrectly.