I have a script that checks leaderboard stats and fills up to 8 slots with their appropriate icons, however, the script only seems to be able to delete icons properly about half of the time. It's a very sloppy setup but other than deletion problems it's served me well.
This is a module script in ReplicatedStorage
Deletion lines start at line 20, and everything else in the script works perfectly fine.
demonstration video: https://streamable.com/9w8fds
local module = {
SortInventory = function(player)
wait(0.1)
print("sort activated")
local leaderstats = player.leaderstats
local supplies = leaderstats.Supplies.Value
local tactical = leaderstats.Tactical.Value
local initiative = leaderstats.Initiative.Value
local research = leaderstats.Research.Value
local slotsUsed = supplies + tactical + initiative + research
local inventory = player.PlayerGui.Inventory.InventoryFrame
if slotsUsed > 8 then
--idk lol
end
local slots = {inventory.Slot1, inventory.Slot2, inventory.Slot3, inventory.Slot4, inventory.Slot5, inventory.Slot6, inventory.Slot7, inventory.Slot8}
for index = 1, #slots do
print("delete")
for i,index in pairs(slots[index]:GetChildren()) do
index:Destroy()
end
local slots = {inventory.Slot1, inventory.Slot2, inventory.Slot3, inventory.Slot4, inventory.Slot5, inventory.Slot6, inventory.Slot7, inventory.Slot8}
for index = 1, #slots do
slots[index]:ClearAllChildren()
slots[index]:ClearAllChildren()
end
end
local debounce = 0
local sorter
local slotsRemoved = 0
print(slotsRemoved.. "slots removed3")
while slotsUsed > slotsRemoved do
print("while do passed")
wait(0.05)
while supplies > slotsRemoved do
print(slotsUsed.. "slots used")
print(slotsRemoved.. "slots removed")
print("supply add icon check passed")
sorter = game.ReplicatedStorage.Supplies:Clone()
sorter.Parent = slots[1]
table.remove(slots,1)
slotsRemoved = slotsRemoved + 1
print(slotsRemoved.. "slots removed2")
wait(0.05)
end
while tactical > slotsRemoved - supplies do
sorter = game.ReplicatedStorage.Tactical:Clone()
sorter.Parent = slots[1]
table.remove(slots,1)
slotsRemoved = slotsRemoved + 1
print(slotsRemoved.. "slots removed2")
print(slots)
wait(0.05)
end
while initiative > slotsRemoved - supplies - tactical do
sorter = game.ReplicatedStorage.Initiative:Clone()
sorter.Parent = slots[1]
table.remove(slots,1)
slotsRemoved = slotsRemoved + 1
print(slotsRemoved.. "slots removed2")
wait(0.05)
end
while research > slotsRemoved - supplies - tactical - initiative do
sorter = game.ReplicatedStorage.Research:Clone()
sorter.Parent = slots[1]
table.remove(slots,1)
slotsRemoved = slotsRemoved + 1
print(slotsRemoved.. "slots removed2")
wait(0.05)
end
if slotsUsed <= slotsRemoved then
break
end
end
end,
}
return module
