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

Shortening Numbers: How? (1000 = 1K)

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

1 comment

0

why dont you just get the length of the string

1 answer

✓ Accepted answer
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

7 comments

0

Soo... do I put this in a local script, module script, or normal script?

0

Whatever sets the value in the gui.

0

oh ok

0

do you need any more help? that 'oh ok' sounded like you need some help idk

0

yeah i do

0

if it isn't, please show me how to (this is inside the script that says the number of coins the player has)

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