How Should I handle many gui buttons

I was wondering which in your opinion is a better way of having “functional” buttons.
I have a gui that consists of many buttons which are used to purchase the things the button suggests. I used to use a script inside them all to run “the fire” event, but for some reason I added a script that “makes the buttons functional.” with a function I am not sure if this is good.

This is probably personal preferece and you may do this in another way, feel free to share.

One script or Many scripts?

here is the script if you care

local Gui
local Event
function Activate(buttons)
if buttons:IsA("ViewportFrame") then
	buttons.Button.MouseButton1Click:Connect(function()
			
			local selectbut = buttons:FindFirstChild("Select")
			if selectbut:IsA("TextButton") then
				selectbut.Visible = not selectbut.Visible
				local typeitem = Frame.Parent.Name
				selectbut.MouseButton1Click:Connect(function()
					
					Event:Fire()
				end)
				
			end
		end)
		
end	
end
for _, buttons in pairs(GUI:GetChildren) do
Activate(buttons)

are all the buttons doing the same thing?

CollectionService is good for multiple object instances with replicable behaviour. Or you can roll out a module script with an embedded table of instances with an AddButton and RemoveButton function and use a connect/disconnect to the MouseButton1Click event in the constructor/destructor.

1 Like

yeah. The event recieves the name variable which will be different , but yeah