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

How to make a money leaderboard change?

Asked by
itsJooJoo 195
8 years ago

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?

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. theCJarmy7 1293 — 8y
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?) itsJooJoo 195 — 8y

2 answers

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
8 years ago
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

0
But afterwards it errored saying it was trying to perform arithmetic on a StringValue and stopped working... itsJooJoo 195 — 8y
Ad
Log in to vote
-1
Answered by
FiredDusk 1466 Moderation Voter
8 years ago

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.

Answer this question