IntValues: Passing the max number limit

hey hi how ya doing?

I’m working on a game and i’ve came to a bug which i’m not sure where to even begin to solve.

In this game you have Coins, these coins are multiplied based on Rebirths you own.
But, After a while i get my Coins at 9.2 quint, And it starts to go into Negetive numbers.


Script
--// Variables
local ds = game:GetService("DataStoreService"):GetDataStore("TestDataStore")

local Cache = {}


--// Functions
game.Players.PlayerRemoving:Connect(function(plr)
	pcall(function()
		ds:GetAsync(plr.UserId, Cache[plr.Name].Coins)
	end)
	
	for i = 1, #Cache do
		if Cache[i] == plr.Name then
			table.remove(Cache, i)
		end
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	local data = nil
	
	pcall(function()
		data = ds:GetAsync(plr.UserId)
	end)
	
	Cache[plr.Name] = {Coins = 0}
	
	if data then
		Cache[plr.Name].Coins = data
	end
end)

The Script above showns what I’ve tried. But i think it’s a failure…

For example, Miner’s haven goes passed 9.2 quint and goes far beyond the limit.
I’m looking for a solution like that. I’m not asking for a Script to be made for me but only what i could try.

Thank you very much.

You’ll have to manually format the numbers. Below are some open-sourced modules:

They’re turning negative because of signed integer overflow. You could use formatting like @A_nxieties suggested or scale down the amount of points given and item values so the numbers wouldn’t get that high.

2 Likes

I don’t think this is what i’m looking for. I’m not looking to see how to abbreviate numbers.
I want to know how i’d go passed 9.2 Quintillion in a IntValue.

1 Like

For representing numbers in large values, you should look into a BigNum implementation. These libraries are typically available to help you represent and perform arithmetic functions across large numbers. For example, RoStrap’s BigNum library. You can check from the page how it performs an operation and outputs a large number.

A different but similar issue where a user tried passing the maximum for double precision floats also had a similar solution proposed where you split the coefficient and the exponent. The number is then represented and handled in scientific notation (math on the exponent and coefficient).

You can’t store the resulting large numbers in an IntValue though. You can either opt to use two IntValues to separate the numbers or rid of IntValues and instead put the variables in your scripts.

2 Likes

You can use the BigInteger module made by @Blockzez to solve this problem. There’s also quite a few others out there.

1 Like