Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to loop through a folder and create GUIs inside of each one?

The title might not have made sense. But I am working on a script whichwill behave to folders' parents and children. The code is supposed to make a gui for each folder it finds, but It only does the children of the base folder. Any help please? Code:

function getItems(obj)
	for _,v2 in pairs(obj:GetChildren()) do
		if v2:IsA("ModuleScript") then
			v2:Clone().Parent = obj
		elseif v2:IsA("Folder") then
			local otherclone = moduleTemplate:Clone()
			otherclone.Name = v2.Name
			pcall(function() otherclone.Text = v2.Name end)
			otherclone.Parent = obj
			otherclone.MouseButton1Click:Connect(function()
				local category = gui.Categories.PG1:Clone()
				category.Parent = gui.Categories
				category.Title.Text = v.Name
				category.Name = v.Name
				for _,v in pairs(category.Items:GetChildren()) do
					if v:IsA("TextButton") then
						v:Destroy()
					end
				end
				getItems(category)
				swipe(gui.Categories.PG1,category)
			end)
			getItems(v2)
		else
		end
	end
end
getItems() -- there was a parameter passed in, but I decided to remove it here

If anyone knows the solution, please reply. Thanks, PoWerofThEePg

1 answer

✓ Accepted answer

Use :GetDescendants() instead of :GetChildren() to search through the entire base folder.

local BaseFolder --base folder instance
for i, obj in pairs(BaseFolder:GetDescendants()) do
	if obj:IsA("Folder") then
		local GUI=Instance.new("ScreenGui")
		GUI.Parent=obj
	end
end

1 comment

0

Thank you! I will use this in my code.

This discussion is preserved as it was. New answers, comments, and votes are closed.