Sorry for the long title, don’t know how else to describe this super specific issue.
-
What do you want to achieve?
I’m making an item shop in my game that functions through SurfaceGUIs. I’m trying to use CollectionService to make the buy button script for each item, so it doesn’t have to be a script in every single button. -
What is the issue?
The buttons do nothing when clicked. I currently have it just printing a line in output to check if the code works and it isnt printing. -
What solutions have you tried so far?
I’ve tried moving the whole SurfaceGui to StarterGui (so that it’ll be in PlayerGui instead of a part in the workspace), which didn’t change anything.
Is there any reason this might not be working? I assume it has something to do with the use of CollectionService, since I have another ImageButton in the same gui that doesn’t use it, and it works fine.
This is the CollectionService LocalScript, it’s located in StarterPlayerScripts.
local CollectionService = game:GetService("CollectionService")
local buttons = CollectionService:GetTagged("ShopItemBuyButton")
for _, button in buttons do
button.MouseButton1Click:Connect(function()
print("bought "..button.Parent.TITLE_NAME.Text)
end)
end
Video of the bug: (The caution symbol button I clicked is the working one I mentioned. I try clicking the shopping cart icons (the buttons using CollectionService) many times, and none of them do anything.)
Image of the button in the explorer: