Gui Button listener

Is there any event listener that will output what button has been press if pressed at all?

I have this game where there is an an array of 8 x 8 squares and I don’t want to add a Mouse1ButtonDown 64 times.

If there is a feature that can return the Instance name (button) that would be great.

If not is there a faster loop way to listen to all 64 buttons at once?

You should use an in pairs function. Like this:

local arrayFrame = script.Parent.ArrayFrame -- The array

for i, v in pairs(arrayFrame:GetChildren()) do -- Get the children from the array, then loop through all the buttons and check if the button has been pressed. The I is the index, the v the actual object.
   if v:IsA("TextButton") or v:IsA("ImageButton") then -- Check if the object is an actual button
       v.MouseButton1Click:Connect(function() -- When a player clicked the button then this even twill fire
         -- Do stuff
       end)
   end
end
1 Like