How would i get all the names the children in a folder and use them as a variable or table or something

local objects = mainFolder:GetChildren() -- how could i get all the names of the children inside this

local start = math.random(1, #objects)

local function nextObject()
	if start == #objects then
		start = 1
	else
		start += 1
	end
	
	return objects[start]
end
local names = {} -- table to store the children names
for _, child in mainFolder:GetChildren() do
  -- iterate through the table using a generic for loop
  table.insert(names, child.Name) -- use the 'table.insert' function to add the value to the 'names' array
end
print(table.unpack(names)) -- Print all the children names
1 Like

ahh thank you, i really need to look into tables, theyre very useful and i dont know how to use them very well

Tables also have different names depending on the structure of the data.

A table would be called an array if its values are in a numerical index.

local tbl = {
    [1] = "value1",
    [2] = "value2",
    [3] = "value3",
    [4] = "value4",
}
print(tbl[3]) -- >> value3

A table would also be called a dictionary if its values are in a non numerical index.

local tbl = {
    ["a_value"] = 3,
    ["another_value"] = 8,
    ["yet_another_value"] = 1,
    ["one_more_value"] = 16,
}
print(tbl["another_value"]) -- >> 8

-- or

local tbl = {}
tbl.something = "lol"
tbl.boolean_value = true
tbl.some_random_number = 420
print(tbl.boolean_value) -- >> true
1 Like