local str = "1234" --input string
local output = "" --result
str = string.reverse(str) --reverses the string so that the , go in the correct place
for i=1 , string.len(str) do --loop through all characters
if i % 4 == 0 then --uses modulo which is the remainder from the division of i/4
output = output .. "," .. string.sub(str, i, i) --adds in the , incuding the number
else
output = output .. string.sub(str, i, i) -- no , needed
end
end
output = string.reverse(output) --puts the string back to its correct format
print(output) -- prints the result
kingdom5 provided this script and it works well but whenever i get past the hundred thousands it adds an extra digit to the thousands place instead of moving to the millions. Please help me

6 comments
Put the whole code in the Code block format please
Please choose appropriate tags too.
What are you trying?
I need a guy to display a number value, And I'm trying to get it to separate the output by 3 to display on the guis as (xxx,xxx,xxx) instead of (xxxxxxxxx)
GUI* sorry my computer autocorrects
Do you think you could help me find a way to make the script reload overtime the leaderstat value is changed? i've already tried and each time it doesn't work. i tried having a function that was called when the value changed but it never changed the text on the guis