Turning a big number to table

i have the code 123456. How would I turn it into a table {“1”, “2”, “3”, “4”, “5”, “6”}

You can use string.split:

local code = string.split(tostring(num), "")
2 Likes

You could do a for loop with the string length and organize the table with string.sub

heres a demonstration of how you could do it?

local number = 123456
local tableofthenumber = {}

for i = 1, string.len(number) do
	local charactertoplace = string.sub(number, i, i)
	table.insert(tableofthenumber, charactertoplace)
end

This script gets the number length (in this case the length of the number 123456 is 6)

then, with the order passed by the INDEX of the for loop, it will get the character of the number (if the index is 4, in this case, the fourth letter is 4)

and add it do the table using table.insert

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.