I am trying to make an inventory thing, but I need items to go from the first slot to the last slot, so there is a int value in each slot telling which number slot it is, from 1 to 30, and also has a boolean value that tells if it is available or not, and I want to make it so that it prioritizes the lowest number in the int value, and it has to be an available slot, but if it isn’t available, it goes to the next lowest number slot until it finds one that is available, but I can’t figure out how to do that.
2 Likes
can you send a picture of what you did?
I edited it so that it has a picture now
do you have an input that says when and what to include in the inventory?
It only includes one item for now
Here would be an idea for a script, I would suggest naming the ItemSlots as “ItemSlot[Number]”, for example: “ItemSlot1”. Would make it a lot simpler and allow this code to work:
local available
function updateAvailableSlots()
available = {}
for i,ItemSlot in pairs(script.Parent.ItemSlotsFrame:GetChildren()) do
if ItemSlot.IsAvailable.Value then
table.insert(available,ItemSlot.SlotNumber.Value)
end
end
table.sort(available)
end
function findNextAvailableSlot()
return script.Parent.ItemSlotsFrame["ItemSlot"..available[1]]
end
3 Likes
Added a slight edit to make it so it returns the Object ItemSlot, making it even simpler.
local LowestSlot = nil
for i,v in pairs(ItemSlotsFrame:GetChildren()) do
if v.IsAvailable.Value then
if LowestSlotNumber == nil then
LowestSlot = {v.SlotNumber.Value, v}
elseif LowestSlot[1] > v.SlotNumber.Value then
LowestSlot = {v.SlotNumber.Value, v}
end
end
end