I know I'm supposed to provide a code, but I'm unsure on this one. I have 48 text buttons all of which I want to do similar code. Whenever I click any of them, I want them to run the same function. Is there an easy way to do this without having to write out 48 different calls?
Thanks.
There actually is a pretty simple way of doing this with a loop. If they all have the same parent, then you could easily just do it this way:
Children=script.Parent:GetChildren() for _,Child in pairs(Children) do --Goes through and assigns the function to all of them. if Child:IsA("TextButton") then Child.MouseButton1Click:connect(function() --Code here for function end) end end
Anyways, this would be the simplest way of doing it. Another way however if they don't have the same parent would be to do this:
Children={} --Make a table of ALL of the Textbuttons here for _,Child in pairs(Children) do --Pretty much the same from here if Child:IsA("TextButton") then Child.MouseButton1Click:connect(function() --Code here for function end) end end
Anyways, I hope this helped you out a bit. If you have any further problems/questions, please leave a comment below, and I'll see what I can do :P