I know how to make it so a single button's mouseclick event connects to a function, but what if I want for example 10 buttons connect to the same function when clicked?
You are able to use a loop to iterate through the buttons. For example, if the script was inside a model with all the parts you want to detect clicks for, you could do something like this:
for _,Part in pairs(script.Parent:GetChildren()) do if Part:IsA("BasePart") then local CD = Instance.new("ClickDetector") CD.Parent = Part CD.MouseClick:Connect(function(Plr) print(Part.Name .. " was clicked by " .. Plr.Name) end) end
This would go through each part in the model, creating a ClickDetector for each and listening for when each of them is clicked.
You can create a function and call upon it every time the event is fired like so:
function wow() print'wow' end b1.MouseButton1Click:Connect(wow) b2.MouseButton1Click:Connect(wow) b3.MouseButton1Click:Connect(wow)