Question about tables

So I have a table full of text buttons, I was wondering if there was a easier way to use a event on everything within the table like say something like this

table = {textbutton1, textbutton2}
table.MouseButton1Clicked:connect(function()
print(“clicked”)
end)

1 Like

Using a generic for loop you can apply code to all items inside of a table. Since your table is an array, you can use the ipairs iterator to iterate over each item 1 by 1 and apply a segment of code each time.

for i, v in ipairs(your_table) do
    -- the variable 'i' is the index in the table where 'v' is
    -- the variable 'v' is the item (in this case, button) in the table
    v.MouseButton1Clicked:Connect(function()
        -- your code here, which will be connected to every item
    end)
end
7 Likes

I was thinking about that but wasnt sure if it would work thanks so much