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

Shortening Numbers: How? (1000 = 1K)

Asked by
AbeTGT 4
4 years ago
Edited 4 years ago

Hey everyone! This is my first post on here so I don't know everything.

Basically, I'm trying to do this for my new game, Part Land. It's kinda like a replica of Ninja Legends. I need help making the numbers shorter, like (example: 1000 will be 1K). I've tried many options and I need help. I already have a leaderboard, it looks like this: then after it's this...

Doesn't work? Part 1: http://mcfightgamepro.coolpage.biz/pic1_abetgt_leaderboard.PNG Part 2: http://mcfightgamepro.coolpage.biz/pic2_abetgt_leaderboard.PNG

Ok, so, i need a script and I need to know exactly what to do. I'm also just a beginner at scripting.

Thanks!

Oh, by the way, I've tried these 2...

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

and also this one..

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

and it did not work. My game called Part Land: https://web.roblox.com/games/4646605474

0
why dont you just get the length of the string greatneil80 2647 — 4y

1 answer

Log in to vote
0
Answered by
palav 104
4 years ago
local Notation = {"K", "M", "B", "T", "Q", "Qu", "S", "Se", "O", "Number", "D"}

local function ConvertNumber(Number)
    for i = #Notation, 1, -1 do
        local v = math.pow(10, i * 3)
        if Number >= v then
            return ("%.0f"):format(Number / v) .. Notation[i]
        end
    end
    return tostring(Number)
end
0
Soo... do I put this in a local script, module script, or normal script? AbeTGT 4 — 4y
0
Whatever sets the value in the gui. palav 104 — 4y
0
oh ok AbeTGT 4 — 4y
0
do you need any more help? that 'oh ok' sounded like you need some help idk royaltoe 5144 — 4y
View all comments (3 more)
0
yeah i do AbeTGT 4 — 4y
0
if it isn't, please show me how to (this is inside the script that says the number of coins the player has) AbeTGT 4 — 4y
Ad

Answer this question