New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

How to insert a comma into a value?

soutpansa 120
1 year ago
Edited 1 year ago

I've got a script that displays the player's level as"'Bounty". If they are level 1 - 999 then it will display level 1 as 1,000, 2 as 2,000, 3 as 3,000 etc. But I'm not sure how to show 1mil bounty when they are level 1000. Here is the script that I'm using:

wait(3)
local Player = game.Players.LocalPlayer

while true do
wait()
if Player.Stats.Pirate.Value == 1 and Player.Stats.Level.Value <= 999 then
script.Parent.Text = "Bounty:"..Player.Stats.Level.Value..",000"
end
end


3
Wiki String Manipulation Shawnyg 4195 — 1y
0
lol User#19524 150 — 1y

2
ABK2017 406
1 year ago
Edited 1 year ago

An example from Desi...Let's take "250000" for example, if we use string.gsub("25000", "(%d%d%d)", "%1,") it will return 250,00 because it searches the string from left to right, so we have to reverse it.

string.reverse("25000"):gsub("(%d%d%d)", "%1,") will return "000,52" so we reverse it again to revert the process. string.reverse("25000"):gsub("(%d%d%d)", "%1,") :reverse() and that's it.

local function addComas(str)
return #str % 3 == 0 and str:reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(2) or str:reverse():gsub("(%d%d%d)", "%1,"):reverse()
end