ImageButton MouseButton1Click on SurfaceGui using CollectionService doesn't work

Sorry for the long title, don’t know how else to describe this super specific issue.

  1. 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.

  2. 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.

  3. 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:
image

Make sure that the button actually have the tag

They all do, I also checked and made sure the spelling and caps matched and it does.
image

Try this:

local CollectionService = game:GetService("CollectionService")
local buttons = CollectionService:GetTagged("ShopItemBuyButton")

for _, button in ipairs(buttons) do
if button:IsA("GuiButton") then
	button.MouseButton1Click:Connect(function()
		print("bought "..button.Parent.TITLE_NAME.Text)
	end)
  end
end

Same result, didn’t change anything. I did a bit of searching and found a potential solution, I’m gonna try using GetInstanceAddedSignal. I’ve seen a few people on other topics say that it could be because the buttons with the tags aren’t loading in time for the script. Only problem is I’m not sure how to implement that.