I have no clue how to explain this but ill do my best. i have a list filled with subtables that go like this {Instance, Name, Amount}, and all of those are set into a single table. i need to iterate through these and only select the first instance of every subtable, so if i had {Slot, "Potion", 1}, {Slot, "Potion", 1}, {Slot, "Potion", 1}, {Slot, "Potion", 1}, {Slot, "Potion", 2}, {Slot, "Potion", 2}, {Slot, "Potion", 2}, {Slot, "Potion", 2}, it would only select the first {Slot, "Potion", 1} and {Slot, "Potion", 2} and then send those two subclasses to a seperate table. PLEASE GOD HELP ME I CANT FIGURE THIS OUT FOR THE LIFE OF ME
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function findFirstByName(targetName, tbl)
for i, subtable in ipairs(tbl) do
if subtable.name then
return subtable
end
end
return nil
end
local InventoryHolder = script.Parent:WaitForChild("InventoryHolder")
local InventorySlots = InventoryHolder:WaitForChild("InventorySlots")
local slots = {}
local items = {}
local itemsFolder = ReplicatedStorage:WaitForChild("Items")
local potion = itemsFolder:WaitForChild("Potion")
-- {Instance, ItemType, Amount, SlotSize}
-- 6, 12, 13, 14
ReplicatedStorage:WaitForChild("UpdateInventory").OnClientEvent:Connect(function(inventory)
-- SET UP SLOT TABLE
for i, label in InventorySlots:GetChildren() do
if label:IsA("TextButton") then
table.insert(slots, {label, name = nil, amount = nil})
end
end
for i, slot in slots do
slot["name"] = inventory[i]["name"]
slot["amount"] = inventory[i]["amount"]
if slot["name"] == "" then -- if slot is empty dont do anything
slot[1].Text = i
elseif slot["name"] ~= "" and slot["name"] then
slot[1].Text = slot["name"]
end
slot[1].MouseButton1Click:Connect(function()
if slot["amount"] then
print(slot["amount"])
end
end)
end
-- SPAWN ITEMS INTO INVENTORY
-- PRINT
print("Slots:", slots)
print("Inventory:", inventory)
print("Items:", items)
end)
** You are now Level 9! **