Help with a simulator capacity upgrade system

Hello!
I’m trying to make a capacity upgrade system for my simulator. I wrote a small script already.

local Player = game:GetService('Players').LocalPlayer
local Max = Player:WaitForChild('BackpackCapacity')
local Whacks = Player:WaitForChild('Whacks')
local MainFrame = script.Parent:WaitForChild('Frame')

local find,insert,remove = table.find,table.insert,table.remove

local CapacityAmounts = {
	
	Capacity1 = {
		Price = 50,
		Capacity = 25
	},
	
	Capacity2 = {
		Price = 100,
		Capacity = 50
	},
	
	Capacity3 = {
		Price = 250,
		Capacity = 100
	},
	
}

Max:GetPropertyChangedSignal('Value'):Connect(function()
	local OldCapacity = Max.Value
	MainFrame.Description.Text = 'Upgrade Capacity from '..Max.Value..' to NEW_CAPACITY?'
end)

MainFrame.UpgradeButton.MouseButton1Click:Connect(function()
	
end)

The problem is, is that I’m trying to get the old capacity and then find the new one. How would I search all the prices in the table to get the old price? I thought about using table.find, but the prices are in sub-tables, and I do not know which price the old one is.

Here, I just made a script that will get the last price by checking Capacities. Just change the “Max” to Max.Value because yours is an instance Value:

function GetLastCapacity(CurrentCapacity)
	local Current
	for i,v in pairs(CapacityAmounts) do
		if v.Capacity == CurrentCapacity then
			local CapacNum = string.split(i, "Capacity")[2]
			Current = tostring(tonumber(CapacNum) - 1)
		end
	end
	local LastCapacity
	if tonumber(Current) > 0 then
		LastCapacity = CapacityAmounts["Capacity"..Current].Price
	end
	if LastCapacity then
		return LastCapacity
	end
end

local LastPrice = GetLastCapacity(Max) --Returns the Last upgrades price.