In my game, I'm creating a lot of textbuttons with a localscript. I essentially want to be able to sense if any of them are clicked, and know which one. Right now I'm accomplishing this by inserting a localscript into every button, but I don't want that many scripts, preferably just one.
I know that there's collectionservice, but I tried using it and it didn't work. Here's my code:
--This is a localscript local collectionService = game:GetService("CollectionService") for _, gui in pairs(collectionService:GetTagged("Button")) do gui.MouseButton1Click:Connect(function() event:FireServer(gui.Name) end) end
I'm not sure if it's possible to do this using collectionservice, and if it isn't how would you do this?
Any help would be appreciated :)