Gui buttons dont work

not the best title, but here’s the script:

for _,button in pairs(visibleFrame:GetChildren()) do
	if button:IsA("TextButton") then
		button.MouseButton1Click:Connect(function()
									
			print("e")
									
			if button:GetAttribute("Selected") == true then

			button:SetAttribute("Selected", false)
			button.BackgroundColor3 = Color3.new(0.352941, 0.352941, 0.352941)
										
										
			elseif button:GetAttribute("Selected") == false then
										
			button:SetAttribute("Selected", true)
			button.BackgroundColor3 = Color3.new(0,1,0)
									
			end								
		end)
	end
end

so heres a video:


as you can see does what its supposed to you can select and unselect it, however when you go to another category and go back it just breaks and i dont know why

the categories are each different frames btw, but i dont think its an overlapping issue because ive tried moving the other frames out of the way and it still does this

2 Likes

Can I see the hierarchy of your gui? This might fix your problem use GetDescendants() instead of GetChildren.

2 Likes

image

i switched it to descendants just in case but its still the same

Can you send the whole script? You can see in the output it is printing 2 times for each click, which means you are connecting the button click each time it’s switched

1 Like

Add more prints to see if the code passes through. Does it print “e”?

1 Like