I am currently working on a plugin and I need to be able to access many different buttons that all do the same thing. Because I am making a plugin, I do not want to use CollectionService because this could possibly interfere with other user’s games. Is there any other way that I can do this?
Yes I am talking about TextButtons, sorry for making it unclear. This would work and I completely forgot to say this in my post, but I am going to also be adding buttons (as in using :Clone()) so I don’t think this will work for that. Do you happen to know how I could use the same script but whenever I add a button to the table it still works?
This may actually be useful. Originally, I did not want to use CollectionService because I am making a plugin and I didn’t want it to interfere with games that use CollectionService. Although, after some testing it seems that plugins using CollectionService don’t actually interfere with the game using CollectionService. I’m going to need to do some extra testing to be sure before I mark this as the solution though. If anybody happens to know and can give me a direct answer that would be great.
Basically connecting every textbutton with a MouseButton1Click by calling the function with the parameter as the textbutton.
If this doesnt work, try to do something similar
Untested code:
function listen(obj)
obj.MouseButton1Click:Connect(function()
print(obj.Name .. " has been pressed")
end)
end
for i, v in pairs(allyourbuttons:GetChildren()) do
if v:IsA("TextButton") then
listen(v)
end
end
allyourbuttons.ChildAdded:Connect(function(child)
if child:IsA("TextButton") then
listen(child)
end
end)