For loop not working for some reason

I am trying to get all of the buttons inside of a surface gui that is in the workspace but for some reason it’s not finding the buttons, I also tried to specify the specific model earlier and it didn’t start the for loop

print("alive")
local buttons = game.Workspace:GetDescendants()
for i, button in pairs(buttons) do
	print("started")
	if button:IsA("TextButton") then
print("found button")
		if button.Parent == "List" then
			print("got list")

			button.MouseButton1Click:Connect(function()
				print("click")
			button.Parent.Parent.Info.PotionName.Text = button.Name
			
		end)
		end
	end
end

also, the model that has all the surface guis IS inside of the workspace

im doing this on a local script that is inside of the playergui

i tried it in a server script and it still didn’t work

You can post a reply of the solution here and mark it as a solution so it can help those who have the same issue in the future

apparently adding a wait at the start of the script fixed the problem, i guess the workspace wasnt fully loaded in or something when i’d play so it didn’t find anything

yeah good call, this is my first time posting on the dev forum. thanks for the tip

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.