Hey, I’ve recently started making a currency system and I want it to have commas with large numbers e.g 100000 would automatically change to 100,000 and 1000000 would be 1,000,000 and would also work with numbers like 121410. I just have no clue how to make it.
If anybody can help me I’d really appreciate it.
^^My one
^^ What I want it to be
Thank’s have a good weekend!
1 Like
I looked at some tutorials on YT but they only have numbers with 100K and 1M.
I’ve also seen this post before and I don’t understand it, maybe you can customize it for like where you create a variable e.g local text = (the stuff u want the commas) because I don’t really understand that post.
Ok now that’s a question, it’s a function which does the job of adding commas.
function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
print(comma_value(100000))--Output 100,000 in string
print(comma_value("51051321312312"))--51,051,321,312,312
1 Like
Do I have to make a module script or can I add it to my main currency script?
(Sorry if I’m annoying you)
Add the function to your currency script and on the part where you set Bux.Value, put that function and the value in paramaters:
if savedStuff then
Bux.Value = comma_value(savedstuff[1])
else
local save = {Bux.Value}
pcall(function()
DataStore:SetAsync(key,save)
end)
end
1 Like