So I'm trying to make an inventory that when you click on the button, It finds the lowest value that is true and prints that, This is what I have and it keeps printing slot3 when it should print slot2
Slots = {
Slot1 = false;
Slot2 = true;
Slot3 = true;
Slot4 = true;
Slot5 = true;
Slot6 = true;
Slot7 = true;
Slot8 = true
}
local Inventory = {}
function Inventory:FindNextSlot(item)
for i,v in pairs(Slots) do
if v == true then
local lowest = i
print(lowest)
break
end
end
end
return Inventory

2 comments
Beat me to it.
You could also use a
pairsand compare the indexes with<, as long as the slots are all the same digit length, the string comparison will work