I am attempting to make a GUI that lets you spawn and edit parts. The function for button presses is contained within a singular local script. I want it to return which descendant was clicked.
When a new button is clicked, the function fires multiple times for every descendant in the list (including each button’s 5 children). The more buttons that are created, the more the function fires, and the laggier and messier things get down the line.
after 1 button is created and clicked
![]()
after 4 buttons are created and one is clicked

local ButtonsTable = {}
local ListofButtons = Instance.new("Folder")
ListofButtons.DescendantAdded:Connect(function() -- fires when the player adds a button to the list
-- this fires once for EVERY DESCENDANT, every time its clicked
for i,v in pairs(ButtonsTable) do
v.MouseButton1Down:Connect(function(ButtonBeingClicked)
print("Button was clicked")
-- the rest of the code
end)
end
end)
I’m not sure how else to optimize an updating table of buttons like this. Are there any other methods instead of DescendantAdded?
