Can I require a module script located inside the Replicated Storage in a script inside a folder that is in the workspace

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?

Script inside the folder:

Module Script:
Screenshot 2023-09-22 102257

dont mind the second time I made a variable for the module script I fix that already but still get the same error message

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.

Folder Script

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

well I found out that its fine although it doesnt work, the error message wasnt for my module script i just need to continue my way of making it

Maybe this will help …

Folder Script:
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

thx, i hate this type of minor mistakes lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.