Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a money leaderboard change?

So I have a leaderstats put in called CC (Cactus Coins, don't judge it.) and I want to make it so that if it's 1,000,000 it'll change to 1M instead of 1,000,000. And if it's a billion, make it 1B, and if it's 140 million, make it 140M rather than all the digits. How would I do that without calling hundreds of lines of code?

2 comments

0

Ok, what I gave you was a function to shorten the numbers. You need a number to put into that function. Get the players Cactus Coins(really?) into the shorten function, and make whatever comes out be the stringValue.

0

Ok alright I was a little bit confused now I get it. Thanks dude! (Also who's gonna be laughing when in 2 years from now Cactus City is gonna be so popular with its trendy cactus coins? HMMMM?)

2 answers

✓ Accepted answer
local letters = {
    "K",
    "M",
    "B",
    "T",
    "QD",
    "QN",
    "SX",
    "SP",
    "O",
    "NO",
    "DEC",
    "UND",
    "DUOD",
    "TRED",
    "QUATD",
    "QND",
    "SXD",
    "SPD",
    "OD",
    "NOVD", -- I really doubt somebody will get more than a novemdecillion
    --put more here
}
local nums = {}

for q=1,#letters do
    local dig = (q*3)+1 --digits
    local letter = 1*(10^(dig-1)) --for dividing purposes
    table.insert(nums,#nums+1,letter) --insert
end

function shorten(num)
    local len = math.ceil(math.log10(num + .5)) --get the digits
    if len>=4 then --check if it's ok to shorten
        for q=1,#letters do
            local dig = (q*3)+1 --smallest number of digits the letter is
            if len <= dig+2 then --check if this digit works
                local toDo = math.floor(num/nums[q]) --the dividing number
                local newNum = toDo..letters[q] --the new num
                return newNum --return it
            end
        end
    end
end

print(shorten(1789000000000000000))--it returns the shortened num

Then do what firedDusk said, use a StringValue when displaying the numbers

1 comment

0

But afterwards it errored saying it was trying to perform arithmetic on a StringValue and stopped working...

Well when changing to 1,000,000 that uses a Number Value or Int Value. But if you are wanting to change it to 1M or 1B then you use a string value.

This discussion is preserved as it was. New answers, comments, and votes are closed.