Math.huge Resetting A Value to 0?

I’m trying to make a infinite storage gamepass for my game and I’m using math.huge to make a value infinite. However I am new to using math.huge

The issue here is whenever i type in math.huge when i am trying to set a value and play the game it just resets.

Solutions i have tried so far are just spamming 9’s to get it to infinite but I feel like that is a inefficient way and not necessary as I want it to actually say “inf” instead of a long number.

Anyway Heres The Full Script:

local sStorage = game:GetService("ServerStorage")
local mps = game:GetService("MarketplaceService")
local player = game:GetService("Players")

local gamepassModule = require(game.ReplicatedStorage.Modules.Gamepasses)

local infiniteStorageId = gamepassModule.gamepass5

local infinity = math.huge

local DSS = game:GetService("DataStoreService")
local backpackdataStore = DSS:GetDataStore("BackpackSave2")

game.Players.PlayerAdded:Connect(function(player)
	
	local boostValues = Instance.new("Folder", player)
	boostValues.Name = "BoostValues"
	
	local MaxCapacity = Instance.new("IntValue")
	MaxCapacity.Name = "CapacityMultiplier"
	MaxCapacity.Parent = boostValues
	MaxCapacity.Value = 2500
	
	local hasInfiniteStorage = Instance.new("BoolValue", player)
	hasInfiniteStorage.Name = "hasInfiniteStorage"
	
	if mps:UserOwnsGamePassAsync(player.UserId, infiniteStorageId) then
		
		hasInfiniteStorage.Value = true
		
		if hasInfiniteStorage.Value == true then
			MaxCapacity.Value = MaxCapacity.Value + infinity
		end
	end
	
	player.CharacterAdded:Connect(function(char)
		
		local backpack = sStorage:WaitForChild("Backpacks").DefaultPizzaBackpack:Clone()
		backpack.CFrame = char.UpperTorso.CFrame * CFrame.new(0, 0, 1) * CFrame.Angles(0, math.rad(270), 0) * CFrame.fromOrientation(90,0,0)
		backpack.BackWeld.Part0 = backpack
		backpack.BackWeld.Part1 = char.UpperTorso
		backpack.Parent = char
		
	end)
end)

math.huge() produces a value which is too large to be stored in an IntValue instance. IntValue instances can be used to store a signed 64 bit number whereas math.huge() produces a number much larger than this. Hence, you can use (2^63)-1 instead to represent a really large number which can be stored inside an IntValue instance.

could I use a number value instead?

Yes, although the limit of a NumberValue instance is smaller, 2^53. This is because the values of NumberValue instances can contain a fractional part.

1 Like

Oh thanks. I used a number value instead and it seemed to have worked. Although it broke my backpack accessory TweenSize measurer system.

You may need to make some modifications to the existing code to accommodate the change.

1 Like

Heres this code I am not to sure how I can fix it as i don’t know which line of code it is.

local amountGui = script.Parent.Amount.BackpackAmount
local char = script.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(char)

local capacityMultiplier = player.BoostValues:WaitForChild("CapacityMultiplier")

amountGui.RedBar.TextLabel.Text = player.leaderstats.Eaten.Value.."/"..capacityMultiplier.Value

player.leaderstats.Eaten.Changed:Connect(function()
	if player.leaderstats.Eaten.Value >= capacityMultiplier.Value then
		player.leaderstats.Eaten.Value =capacityMultiplier.Value
		amountGui.RedBar.TextLabel.Text = player.leaderstats.Eaten.Value.."/"..capacityMultiplier.Value
	end
	
	amountGui.RedBar.TextLabel.Text = player.leaderstats.Eaten.Value.."/"..capacityMultiplier.Value
end)

player.BoostValues.CapacityMultiplier.Changed:Connect(function()
	amountGui.RedBar.TextLabel.Text = player.leaderstats.Eaten.Value.."/"..capacityMultiplier.Value
end)

player.leaderstats.Eaten.Changed:Connect(function()
	amountGui.RedBar.Progress:TweenSize(UDim2.new(player.leaderstats.Eaten.Value / capacityMultiplier.Value, 0, 1, 0))
end)