How can I store leaderstat values above 9.2 quintillion?

Hello everyone. I am making a simulator type game and I cannot seem to figure out how to store values above 9.2 quintillion in leaderstats. (I do not want to use someone else’s module.)

I have tried looking for solutions, but I can only find string compressors.

Thanks for your help!

I don’t know of a way to store a number accurately, maybe somebody can answer that part.

But if you’re okay with losing some about of specific data, you can simply take a certain amount of the number, and then replace the rest with powers of ten. For example, the number 5 trillion would simply be 5*10^12. All you’d have to do is store the number up front and the number of 0’s after it. But that won’t allow for math really.

Another method with similar data loss would be to simply shrink the number down and then just describe how big of a number it is, then do math with that. So 5B - 3B = 2B, would be an example. For higher numbers, you’d just have to convert it a bit. So 1T would just be 1000B for the math, or take the billion and turn it into a decimal of a what a trillion would be 0.001T.

Thank you, I understand how converting numbers works but how can I display the value on the leaderstats when it’s above 9.2 quintillion?

Hey, try using my code to abbreviate large numbers.

local short = {"", "K", "M", "B", "T"} -- Add more

local function abbrievateNum(number)
local str = tostring(math.floor(number))
return string.sub(str, 1, ((#str+2)%3) + 1)..short[math.floor((#str-1)/3) + 1]

This code is taken from my topic featured on my profile!

I’m not sure if there is a way as it doesn’t seem that you can use anything other than NumberValues. However, you can simply make your own leaderstat GUI system or use somebody else’s.

Actually, you can just use an IntValue as it seems to automatically abbreviate large numbers.
Nvm again, both Number and Int values do that, but it seems to go up to a max of a billion. Perhaps a custom leaderboard will be needed after all.

Yes, but not till 1M. If he really needs to abbreviate it on GUI and all that, I suggested my above topic and code used by many people!

Yeah, it seems that way. Your code seems way more efficient than the function I wrote a year ago:

function CompressNumber(number)
	if number == 0 then
		return '0'
	local abv = {'','K','M','B','T','Qa','Qi','Sx','Sp','Oc','No','Dc','Ud','Ud','Dd','Td','Qad','Qid','Sxd','Spd','Ocd','Nod','Vg','Uvg','Uvg','Dvg','(e70)','(e71)','Tvg','(e73)','(e74)','Qavg','(e76)','(e77)','Qivg','(e79)','(e80)','Sxvg','(e82)','(e83)','Spvg','(e85)','(e86)','Ocvg','(e88)','(e?)'}
	local output
	for i,v in pairs(abv) do
		local n = 1000^(i-1)
		if math.abs(number) >= n then
			output = tostring(math.round(number/n))..v
			return output
	return output

If I were to redo it, I’d have split it up by 3’s, but even then your code seems better. I’ll have to look into more string related stuff.

I’d like your reply, but again, I’m on a 9 hour cooldown for likes.

1 Like

that’s not what I need, I need to display numbers above 9.2 quintillion. This will display abbreviations. I also need to be able to perform math on the number. Thanks for trying to help!

1 Like

I think you can combine @Moneypro456789’s abbreviation with my post about doing math:

1 Like

IntValue and NumberValue objects have a maximum value of 2^63 - 1, which is approximately 9.2 quintillion.

Honestly, your best bet is to save and calculate the player’s data through scripts themselves, because numerical values in scripts can take on values as large as 2^1024 - 1. Just send the relevant data to a StringValue in the leaderstats folder for display purposes only.

1 Like

You could eventually fix the Main Value limit to 9 Quintillion and add a Multiplier Value to go above it.
Doing it allow you do go at (9 Quintillion x 9 Quintillion) which is better than nothing.

And if you need to go again above it you can add a second multiplier and do (9 Quintillion x 9 Quintillion) x 9 Quintillion xD

local Coins = script.Coins --Your Coins IntValue
local Multi = script.Multiplier --Your Multiplier NumberValue

local Limit = 9000000000000000000 --Maximum Coins Value

local AddCoins = 5000000000000000000 --Add This Number of coins
local RemoveCoins = 1000000000000000000 --Remove This Number of coins

Coins.Value = Limit
Multi.Value = 1

local function RoundNumber(num, numDecimalPlaces)
	return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))

local Percentage = Multi.Value + AddCoins * 100 / Limit
Multi.Value += RoundNumber(Percentage / 100, 1)

local Percentage = Multi.Value + RemoveCoins * 100 / Limit
Multi.Value -= RoundNumber(Percentage / 100, 1)

--Show Coins Amount in text
local Text = tostring(Coins.Value * Multi.Value)

how would this work? I don’t entirely understand