So, what i mean to say “show the items” it means that the inventory just needs to demostrate the items that are in a player’s backpack, or basically meaning that a InventoryModule needs to get the player backpack data and the player, and puts the items that are on the data on a Table/Dictionary, most like this:
local PlayerBackpackDictionary = {
PlayerItems = {
ItemOne = PlayerBackpack:WaitForChild("ItemOne");
ItemTwo = PlayerBackpack:WaitForChild("ItemTwo")
--And then it goes...
}
}
Observation: I don’t know exactly how to do this, but i was thinking of Serialization method.
On the InventoryClient, it would use require() on the module (Also, InventoryModule is parent of InventoryClient, so it would be easier to require it) and then, the InventoryClient would check the Table/Dictionary and would clone the slots the times of #PlayerItems (I think also that this is not the best way to do it), i don’t know exactly how to put the items on the slots, so i need help in that also.
This is everything by now. Remembering that it just needs to show different items on the slots.
Im not 100% sure I understand what you mean but this could help
The module script to get the items from the player’s backpack would look something like this, where you would have a GetPlayerBackPackDictionary method that returns the player’s items.
local InventoryModule = {}
function InventoryModule:GetPlayerBackpackDictionary(player)
local backpack = player:FindFirstChild("Backpack")
if not backpack then
return { PlayerItems = {} } -- Return an empty dictionary if no backpack is found
end
local PlayerBackpackDictionary = { PlayerItems = {} }
for _, item in pairs(backpack:GetChildren()) do
if item:IsA("Tool") then
PlayerBackpackDictionary.PlayerItems[item.Name] = backpack:WaitForChild(item.Name)
end
end
return PlayerBackpackDictionary
end
return InventoryModule
Then on the client you would have a local script which would use the method GetPlayerBackPackDictionary to get the items and then loop through the items to make ‘slots’ for each of them.
local InventoryModule = require(ReplicatedStorage:WaitForChild("InventoryModule"))
local backpackData = InventoryModule.GetPlayerBackpackDictionary(player)
local index = 1
for itemName, item in pairs(backpackData.PlayerItems) do
local slot = slotTemplate:Clone()
slot.Name = itemName
slot.Visible = true
slot.Parent = inventoryGUI
index = index + 1
end