So Im practicing to do an Inventory system from skratch and see if I can make it, I try using a module script to manage the Inventory and when I click the part I want to add the part inside the inventory but it doesnt do it so after seeing this error message: “Requested module experienced an error while loading - Client - CoreScripts/AvatarContextMenu:61” I was wondering if I was doing something wrong or if itsnt possible?
I don’t see why you couldn’t … But, I’m not messing with a picture of a script. Use the </> option and post your scripts so they can be easily copied and looked over in the stupid.
local BoxesFolder = script.Parent
local RS = game:GetService("ReplicatedStorage")
local InventoryManager = require(game:GetService("ReplicatedStorage"):WaitForChild("InventoryManager"))
for i, box in BoxesFolder:GetChildren() do
if box:IsA("Part") then
local CD = Instance.new("ClickDetector")
CD.Parent = box
CD.MouseClick:Connect(function(Player)
if not Player.Backpack:FindFirstChild(box.Name) then
local Tool = RS:WaitForChild("Items"):WaitForChild(box.Name):Clone()
Tool.Parent = Player.Backpack
local PlayerInventory = InventoryManager.New(Player)
PlayerInventory:AddItem(tostring(Tool.Name))
for _, item in ipairs(PlayerInventory) do
print(item)
end
else
print("Already Have Item")
end
end)
end
end
Module Script:
local Inventory = {}
Inventory.__index = Inventory
local PlayerInventories = {}
function Inventory.New(Player)
local PlayerInventory = {}
setmetatable(PlayerInventory, Inventory)
PlayerInventories[Player.UserId] = PlayerInventory
return Inventory
end
function Inventory:AddItem(Player, Item)
table.insert(self, Item)
end
return Inventory
local BoxesFolder = script.Parent
local RS = game:GetService("ReplicatedStorage")
local InventoryManager = require(game:GetService("ReplicatedStorage"):WaitForChild("InventoryManager"))
for _, box in pairs(BoxesFolder:GetChildren()) do
if box:IsA("Part") then
local CD = Instance.new("ClickDetector")
CD.Parent = box
CD.MouseClick:Connect(function(Player)
if not Player.Backpack:FindFirstChild(box.Name) then
local Tool = RS:WaitForChild("Items"):WaitForChild(box.Name):Clone()
Tool.Parent = Player.Backpack
local PlayerInventory = InventoryManager.New(Player)
PlayerInventory:AddItem(box.Name) -- Use the item name here
for _, item in ipairs(PlayerInventory) do
print(item)
end
else
print("Already Have Item")
end
end)
end
end
Module Script:
local Inventory = {}
Inventory.__index = Inventory
local PlayerInventories = {}
function Inventory.New(Player)
local PlayerInventory = {}
setmetatable(PlayerInventory, Inventory)
PlayerInventories[Player.UserId] = PlayerInventory
return PlayerInventory -- Return the PlayerInventory, not Inventory
end
function Inventory:AddItem(Item)
table.insert(self, Item)
end
return Inventory