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

How do I abbreviate large numbers on the leaderboard?

Asked by
Retroc 35
9 years ago

Hi. I've been asking this question to a lot lately, and no one seems to be able to help me. I am making a tycoon game, and it's getting pretty substantial and I need a way to convert/abbreviate the value of a player's Cash on the leader board. (Example: 100,000,000 = 100M, similar to what Berezaa does in some of his games.) I have this script put together but it doesn't work and output is not spitting anything out. The leaderstat is an Intvalue, if that's important. And also if someone could tell me what kind of script to use (local or regular) and where to place the script in the game, that'd be really helpful. I should also mention that in game.ServeStorge I have an item called MoneyStorage that houses each player's money. This helps prevent certain exploits.

function Convert(num)
local x = tostring(num)
if #x>=16 then
local num1 = (#x-15)
return x:sub(0,(num1)).."."..(x:sub(#x-13,(#x-13))).."QN+" --Quintillion
elseif #x>=13 then
local num1 = (#x-12)
return x:sub(0,(num1)).."."..(x:sub(#x-10,(#x-10))).."QD+" --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

local number = game.Players.LocalPlayer.leaderstats.Cash
game.Players.LocalPlayer.Cash.Value.Changed:connect(function()
    number.Value = Convert(game.Players.LocalPlayer.Cash.Value) 
end)

0
You need to change the IntValues to StringValues in the leaderboard, and then when you process the numbers in the script just use tonumber(). ChipioIndustries 454 — 9y

Answer this question