How to put values from multiple folders

  1. Basically, I want to clone a gui into a scrolling frame based on how many folders are in a player. It will then clone, and change each frame textlabel to the value in the folder

  2. This seems difficult due to the fact that you have to go through each folder and set each value differently from each other. I have no idea how to achieve this.

So let me get this straight, you want to get how many folders are in a player, and clone a certain GUI based on how many folders they have?

Also, if you could, can you tell me what you’re trying to do with it so I can understand completely what your trying to do?

Yea, I have kind of a script going which gets children and counts how many children and prints. Now trying to figure out how to clone it based on the number of children.
I am trying to clone a template to scrolling frame based on how many children there are.

Script I was making:

local player = game.Players.LocalPlayer
local TextBox = script.Parent
TextBox.FocusLost:Connect(function(enterPressed, inputThatCausedFocusLost)
	if enterPressed then

	local p = game.Players:FindFirstChild(script.Parent.Text)
	local count = 0
		print(#p.Character.Arrests:GetChildren())
	

			
		end

	end
end)

This will print the folders that are in a character and the amount of them.

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Functions
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local FolderTable = {}
		
		for i, child in ipairs(character:GetChildren()) do
			if child:IsA("Folder") then
				table.insert(FolderTable, child.Name)
			end
		end
		
		print(FolderTable, #FolderTable)
	end)
end)

This will print the folders that are in a PLAYER and the amount of them.

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Functions
Players.PlayerAdded:Connect(function(player)
	local FolderTable = {}
		
	for i, child in ipairs(player:GetChildren()) do
		if child:IsA("Folder") then
			table.insert(FolderTable, child.Name)
		end
	end
		
	print(FolderTable, #FolderTable)
end)

How would I clone based on the amount of children?

You would have to fire a remote event to a client if you want to make a GUI appear on the client based on the amount of children.

Example of how to do it:

First, add a remote event in Replicated Storage:
image

Then add a server script and paste this into it:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Functions
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local FolderTable = {}
		
		for i, child in ipairs(character:GetChildren()) do
			if child:IsA("Folder") then
				table.insert(FolderTable, child.Name)
			end
		end
		
		ReplicatedStorage.RemoteEvent:FireClient(player, tonumber(#FolderTable)) -- Send the client the amount of items in "FolderTable"
	end)
end)

Then add a localscript into StarterPlayerScripts:
image

Paste this into it:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local Player = Players.LocalPlayer
local ScrollingFrame = Player.PlayerGui.YourScrollingFrame -- Reference your scrolling frame

--//Functions
ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(FolderAmount) -- FolderAmount is the value sent in from the serverscript
	if FolderAmount == 1 then
		local YourGui1 = Player.PlayerGui.YourGui1:Clone() -- Reference your GUI
		YourGui1.Parent = ScrollingFrame
	elseif FolderAmount == 2 then
		local YourGui2 = Player.PlayerGui.YourGui2:Clone() -- Reference your GUI
		YourGui2.Parent = ScrollingFrame
	end -- etc, etc
end)

How would I then make it so the text in the frame was the value inside a folder, if there are multiple folders?

You would have to pass that over in the remote event. I’ll make you a quick script edit real quick.

I just don’t get how I would do that, could you give an example?

Wait, you want the script to grab every value from all the folders there are and send them through the remote event right?

It’s really hard to explain, so once they are all cloned, I want to set the value in the folder to the text, but there is 2 folders, how would I do that?

(this is an edit of my previous script)

Example of how to do it:

First, add a remote event in Replicated Storage:
image

Then add a server script and paste this into it:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Functions
Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	Folder.Name = "Folder"
	Folder.Parent = player
	
	local Value = Instance.new("IntValue")
	Value.Name = "Value"
	Value.Value = 100
	Value.Parent = Folder
	
	local FolderTable = {}
	local TextTable = {}
	
	for i, folder in ipairs(player:GetChildren()) do
		if folder:IsA("Folder") then
			table.insert(FolderTable, folder.Name)
			
			for i, value in ipairs(folder:GetChildren()) do
				if value:IsA("ValueBase") then
					table.insert(TextTable, value)
				end
			end
		end
	end
	
	ReplicatedStorage.RemoteEvent:FireClient(player, #FolderTable, TextTable)
end)

Then add a localscript into StarterPlayerScripts:
image

Paste this into it:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local Player = Players.LocalPlayer
local ScrollingFrame = Player.PlayerGui:WaitForChild("YourScreenGui").YourScrollingFrame

--//Functions
ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(FolderAmount, TextTable)
	if FolderAmount == 1 then
		local YourGui1 = ReplicatedStorage.YourGui1:Clone()
		YourGui1.Parent = ScrollingFrame
		
		for i, child in ipairs(TextTable) do
			YourGui1.YourTextLabel.Text = YourGui1.YourTextLabel.Text .. ", " .. tostring(child)
		end
		
	elseif FolderAmount == 2 then
		local YourGui2 = ReplicatedStorage.YourGui2:Clone()
		YourGui2.YourTextLabel.Text = tostring(TextTable)
		YourGui2.Parent = ScrollingFrame
		
		for i, child in ipairs(TextTable) do
			YourGui2.YourTextLabel.Text = YourGui2.YourTextLabel.Text .. ", " .. tostring(child)
		end
	end -- etc, etc
end)
local player = game.Players.LocalPlayer
local playerFolder = player:WaitForChild("Folder")
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local scrollingFrame = screenGui:WaitForChild("ScrollingFrame")

function updateGui()
	for _, folder in ipairs(playerFolder:GetChildren()) do --iterate through folders in main folder
		if folder:IsA("Folder") then
			local frame = Instance.new("Frame")
			frame.Parent = scrollingFrame
			frame.Name = folder.Name
			frame.Position = UDim2.new() --specify a position here
			frame.Size = UDim2.new() --specify a size here
			--change other properties of frame here
			for _, value in ipairs(folder:GetChildren()) do --iterate through values in each folder
				local label = Instance.new("TextLabel")
				label.Text = tostring(value.Value)
				label.Parent = frame
				label.Position = UDim2.new() --specify postion of label here
				label.Size = UDim2.new() --specify size of label here
				--change other properties of label here
			end
		end
	end
end

task.spawn(function()
	while task.wait(5) do
		updateGui()
	end
end)