Hello. I seem to be having a problem with tables inside of tables.
I’m lazy and I didn’t want to create 40 different tables do I made some tables inside of a table to have multiple values in one row. The idea was that there were multiple values, each tied to a color3value which I would change a gui’s backgroundcolor3 to it, every line that is referenced is based on “numb” which is a number that changes and corresponds to a line. I was able to get most of what I needed working but two lines weren’t working how I expected them to. The code is below: (this is all in a localscript but I don’t think that matters)
local values = {
value1 = {red, orange, green, purple} -- Examples
value2 = {pink, green, red, blue} -- Examples
}
function placeholder()
for i = 1, table.getn(values[numb]) do
local clonepart = script.Parent.ItemToClone:Clone()
clonepart.BackgroundColor3 = values[numb][i]
clonepart.Parent = script.Parent.List
clonepart.Name = "cloned"
clonepart.Visible = true
end
end
placeholder()
I modified the code a little bit like changing references to “ItemToClone” or “placeholder”.
If you can show me what the problem is that would be appreciated, thank you!
I’m not sure if you were talking about this, but this is what I did.
It got the total count of the items in the table
local values = {
value1 = {"red", "orange", "green", "purple"} ,
value2 = {"pink","green", "red", "blue"}
}
local TotalValue = 0
for _,v in pairs(values) do -- v is the tables inside of the ** Main Table **
TotalValue += 1 -- Incase you want to count the tables inside of the ** Main Table ** as part of the count
TotalValue += #v
end
print(TotalValue)
^ The add one is incase you want to add the tables inside of the table as a count.
local values = {
value1 = {"red", "orange", "green", "purple"} ,
value2 = {"pink","green", "red", "blue"}
}
local TotalValue = 0
for i,v in pairs(values) do
for a,b in pairs(v) do
TotalValue += 1
end
end
print(TotalValue)```