Collection Service not running when TextButton Is clicked

So I’m having a problem where this script won’t work correctly

for i,v in game.CollectionService:GetTagged("Shop") do
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			game.ReplicatedStorage.market:FireServer(v.Name)
		end)
	end
end

The collection function runs but the MouseClick function doesn’t run when It’s supposed to.

1 Like

Hmm, try printing the name of the textbutton to see if it actually gets it:

for i,v in game.CollectionService:GetTagged("Shop") do
	if v:IsA("TextButton") then
        print(v.Name)
		v.MouseButton1Click:Connect(function()
			game.ReplicatedStorage.market:FireServer(v.Name)
		end)
	end
end

Also consider using V.Activated:Connect() instead of V.MouseButton1Click:Connect(), activated works for just about every device (not sure about console though)

1 Like

Still not working. It does return all of the text buttons. I tried activated. Didn’t work either. In console there are no errors. The function just isn’t running.

1 Like

can I see the properties of the textbutton?

1 Like

There are multiple thats why its collection service. But here is one of them. All of them are the same properties but they just have different names and text




1 Like

is there anything above the textButton?

1 Like

What do you mean, above the textbutton? There is nothing currently above it.

1 Like

Ok wait I just realized the problem I think, the reason it is printing the things name is due to how roblox is, for whatever reason tags wont be cloned along with Instances, what it is printing is the textButtons inside of starterGui, and not the players UI, cause well, again, cause they dont get cloned with them.

To make sure I am right, what I want you to do is:
Playtest → Players → YourPlayerInstance → PlayerGui → Your UI → One of the buttons → tags:
Tags is in the properties, if its empty please tell forth lol

what is shop? A screen gui or what?

Thats not relevant. Its just the tag name.

You mean it doesn’t print all of the textbuttons?

They said it does return all of them, so yes it prints them. Unless bad grammar is getting the best of us

1 Like

No, didn’t work. Man this is annoying .

textbuttons can also be glued on surface guis, this is just a blind guess on what this guy is trying to achieve on what context

My mistake I read it incorrectly

Its a screen gui. Im making a rank center :skull:

So there are no tags? If so I’d advise looping through the items in the UI that are shop buttons without tags, cause well tags are silly lol

Gonna be real with you I read it wrong the first time when you quoted it and I thought you were right :sob:

As @FroDev1002 said, you can try assigning the functions everytime a button is added.

Use this event to detect when a button is added

No, the tags are there … Remember I said the for loop was running just the v.MouseButton1Click function wasn’t working…

1 Like

First off, if there is a button unlocking the mouse, then make the zindex 0, otherwise, just make the button zindex like 22 just to test, also just a question, do u use context action service that uses mouse button 1 up or something like that?

1 Like