Finding the greatest value

I am trying to make an “Equip Best” button similar to the one in PSX. But how do I figure out which value in the inventory is the greatest?

Here is an example of what an inventory could look like:

inventory
Basic Sword

Damage = 10

Basic Ability

Damage = 25

Gold Sword

Damage = 27.5

Any help is greatly appreciated!!
Happy new year as well to all!

I would create a value Called max = 0, go through all the items in the inventory, if the damage of any item in the inventory is greater than max, then set max equal that item
ex.

local BestItem = nil
local Max = 0

for i,v in pairs(Inventory) do
   if v.Damage > Max then
      Max = v.Damage
      BestItem = v
   end
end

Thank you! I will try it out and let you know how it goes :slight_smile:

Sorry for the late reply. I forgot to come back here after testing it.
It worked though! I will be setting your message as the solution