In pairs() do Question

I have multiple templates in the same frame, why is only one button appearing to be visible?

Script:

for _, Button in pairs(Main.Template.Container.DropDown:GetChildren()) do
			if Button:IsA("TextButton") then
				if Button.Name == "Button" then
					Button.Visible = true
				end
			end
		end

image

Thats because GetChildren returns only the object children and not the childrens children. Use :GetDescendants() for that

for _, Button in pairs(Main.Template.Container.DropDown:GetDescendants()) do
	if Button:IsA("TextButton") then
		Button.Visible = true
	end
end
1 Like

Hm… This didn’t seem to change anything.

Are all the buttons you want visible name Button

Are the templates cloned?

This text will be blurred

-- This must a client script

local function loopThroughObjects(objectToLoopThrough : Instance): {}
   local tableToReturn = {}
   for k, v in pairs(objectToLoopThrough:GetChildren()) do
      if v:IsA("TextButton") and v.Name == "Button" then
         table.insert(tableToReturn, v)
      end
   end
   return tableToReturn
end

for k, v in pairs(loopThroughObjects(Main.Template.Container.DropDown)) do
   v.Visible = true
end

1 Like

try this

for i, Button in ipairs(Main.Template.Container.DropDown:GetDescendants()) do
	if Button:IsA("TextButton") and Button.Name == "Button" then 
		Button.Visible = true
	end
end
1 Like

I didn’t understand so well, do you have more “Templates” inside “Main”?

2 Likes

if thats the case, try:

for _, Template in ipairs(Main:GetChildren()) do
    if Template.Name == "Template" then
        for i, Button in ipairs(Template.Container.DropDown:GetChildren()) do
            if Button:IsA("TextButton") and Button.Name == "Button" then
                Button.Visible = true
            end
        end
    end
end
1 Like