Numbers turning negative

In my game, once a player’s currency reaches a certain number is turns negative. I have had this problem before but never found an ideal solution to it. The player’s currency is stored in an IntValue.
Screen_Shot_2020-11-13_at_6.21.41_PM
Is there any way around this?

1 Like

It would sure be helpful if the code was provided.

Running on assumptions, I could say maybe place it in a NumberValue instance instead of an IntValue?

4 Likes

If int values exceed a maximum value, they reset at the minimum. This means the amount you are storing is too large.

The highest int value is 2,147,483,647

1 Like

This is the code

script.Parent.Click.MouseButton1Down:Connect(function()
	script.Parent:TweenSize(UDim2.new(0.057, 0,0.105, 0), "In","Linear",0.1,true)
	local CoinPetMultiplier = PetMultiplierModule:GetPetMultipliers(Player, "Coin")
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,12514986)then
		Player.leaderstats.Clicks.Value = Player.leaderstats.Clicks.Value 
			+ ((1 + Player.PlayerUpgradeFolder.ClickAdds.Value) * (Player.PlayerUpgradeFolder.Multiplyer.Value * CoinPetMultiplier)) * 2
		wait(.1)
	else
		Player.leaderstats.Clicks.Value = Player.leaderstats.Clicks.Value 
			+ (1 + Player.PlayerUpgradeFolder.ClickAdds.Value) * (Player.PlayerUpgradeFolder.Multiplyer.Value * CoinPetMultiplier)
		wait(.1)
	end
	wait(.1)
	script.Parent:TweenSize(UDim2.new(0.074, 0,0.133, 0), "Out","Linear",0.1,true)
end)

Thanks once I replaced it, it exceeded the maximum value.

1 Like

Actually this is for signed 32-bit integers, in Roblox IntValue are signed 64-bit integers.
In Roblox the highest IntValue can store is 2 ** 63 - 1 (9.223.372.036.854.775.807) (but that’s pointless as there’s no true integers in Luau)

2 Likes