I don’t recommend using your method. What you should do is return a function for the text;
function addComma(number)
local left, num, right = string.match(number, '^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
All you have to do is call the function, and the function returns the text with commas. I use this for any game I have that I need currency displayed. Hope this helped!
Also please note, this doesn’t add M+ , K+ , this adds a comma like it does in the Leaderboard. If you wish to know how to add M and K’s to your text here is a video that can explain it well for you;
What you do with that is just change what he does for the leaderboard and do it in the text.