Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I shorten / abbreviate large numbers on the leaderboard? (E.X: 100M)

Asked by
Retroc 35
9 years ago

Hi, sorry that there is nothing to 'fix' but rather I am asking for help on this. I really don't know where to start on the script and if someone could at least lead me in the right direction so I know how to abbreviate large numbers, that'd be great.

Something similar to what berezaa does in Miner's Haven or 2PGFT.

2 answers

Log in to vote
2
Answered by 9 years ago

Here is a little function I wrote.

function Convert(num)
local x = tostring(num)
if #x>=13 then
local num1 = (#x-12)
return x:sub(0,(num1)).."."..(x:sub(#x-10,(#x-10))).."Q+" --Quadrillion
elseif #x>=10 then
    local num1 = (#x-9)
    return x:sub(0,(num1)).."."..(x:sub(#x-7,(#x-7))).."B+" --Billion
elseif #x>= 7 then
 local num1 = (#x-6)
 return x:sub(0,(num1)).."."..(x:sub(#x-5,(#x-5))).."M+" --Million
elseif #x>=4 then
    return x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+" --Thousand
else
return num
end
end
Convert()-- whatever your currencys Heiracy is
1
shortened: function Convert(n)local l=math.min(5,math.floor(math.log10(n)/3))return l==0 and n or math.floor(n/1000^l+.5)..({'K','M','B','T','Q'})[l]..'+'end 1waffle1 2908 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

The simplest way is to use if statements, but this also means you'll need two different values.

One will be either the IntValue or NumberValue for how much cash (or ore, experience, ) the player has. Put this probably inside the PlayerGui. The other should be the StringValue (since it contains letters in addition to numbers) that goes on the leaderboard.

Whenever the player gets cash, increment the IntValue. Next have something in the script kind of like this:

Cash = Player.PlayerGui.IntValue
AbbreviatedCash = YourLeaderStatsHere.StringValue

...

Cash = Cash+50

If Cash > 1000 then
AbbreviatedCash =math.floor (Cash/1000).."K"
elseif Cash >1000000 then
AbbreviatedCash = math.floor(Cash/1000000).."M"
elseif Cash < 0 then
AbbreviatedCash = "You're broke"
else
AbbreviatedCash = Cash
 end

Something like that, hope this works and helps :D

0
just a question...where do i put the script? in server script service or in the text because i wanna show it at a gui...I'm at developing btw a65654321 0 — 4y

Answer this question