How would I create a maximum value for an item stack?

Hello, DevForums! Last post, I found my answer to how I would be able to put an item clicked on into a player’s inventory. This uses the same inventory, but instead, I am wondering about how to create a maximum item stack amount, which would stop the player from picking up more of the same item once it hits the amount limit. I have tried to make it so that when the player clicks an item, it compares it to a constant value that defines the maximum amount of times item can be stacked to the current amount the player has, in order to get it to prevent the player from picking up more when they already have the maximum amount, but it continues to allow it instead.

The script that detects if the item has the maximum amount (maximum amount is 3):

v.ClickDetector.MouseClick:Connect(function ()
		if inventory[v.Name] then
			while true do
				if inventoryframe[v.Name].AmountValue.Value <= game.ReplicatedStorage.ItemInfo.MaximumValues.Pants2.Value then
					inventory [v.Name] += 1
					inventoryframe[v.Name].AmountLabel.Text = inventory[v.Name]
					inventoryframe[v.Name].AmountValue.Value = inventory[v.Name]

The result:
robloxapp-20210808-2316078.wmv (622.6 KB)

if inventoryframe[v.Name].AmountValue.Value <= 3 then

I have also tried turning the part of this script that compares the two numbers (specifically the second half after the less than or equal to sign) into a number (3), but it still doesn’t work.