How to grab everything in a table, and use # to make it an int

So, I wanted to test out something that grabs everything in a table, because I’m trying to learn new things. But, I tried using
for _,v in pairs(tables:GetChildren()) do local value = #v print(value) end

but that didn’t work. How can I do this?

Assuming you want to convert all the objects in the table to an int, you could do something like:

local table1 = {"1","2","etc."}
local table2 = {}
for _,v in pairs(table1) do
    table.insert(table2, tonumber(v))
end

Although this will return errors when you convert strings that have letters in them.

Is this what you meant?

I got an error saying : (number expected, got nil). Also, my table are strings. So, I think that’s the problem.

Here is what your code does:

for _,v in pairs(tables:GetChildren()) do
Do the following for every single object in tables (which is an Instance, such as a Model or Part)

local value = #v
Take the “count” of the object. If the object were a table with an array, then value would be the amount of things in the array. If the object were a string, then value would be the length of the string. However, v is an Instance, because it came from GetChildren, and I’m not sure if the # operator would make any sense on an Instance.

print(value) end
Print whatever #v is, which is likely to be nil, or the script will error before reaching this.

I think you just posed the question poorly.

Yeah, that is the problem. You can’t convert letters like “a” “b” and “c” to integers.

This code is from StackOverflow:

local function ToInteger(number)
  return math.floor(tonumber(number) or error("Could not cast '" .. tostring(number) .. "' to number.'"))
end

This essentially prints that there was an error instead of actually causing an error and stopping the code.

I was using that as an example.