I have a problem with my module script/inventory system

the problem is that its not working

the problem is that its not working

function module.equipItem(Player, ItemName, Count)
	local Data = module.Profiles[Player]
	if not Data then
		warn("Data not found for player")
		return
	end

	warn("start1")

	-- Check if the item exists in the game's ReplicatedStorage.Inv.Materials
	local part = game.ReplicatedStorage.Inv.Materials:FindFirstChild(ItemName)

	if not part then
		warn("Item not found in ReplicatedStorage.Inv.Materials")
		return
	end

	
	local partcategory = part:GetAttribute("Category")

	warn("start2")

	
	local itemsinfo = require(script.Parent.itemsinfo) 
	local itemInfo = itemsinfo.Items[partcategory] and itemsinfo.Items[partcategory][ItemName]
print(part)
	print(itemInfo) -- Use print to check the retrieved item information

	if not itemInfo then
		warn("Item information not found in itemsinfo module")
		return
			end

		warn("start3")
    

local canEquip = itemInfo.Equipable

if canEquip then
	warn("start5")

	local character = Player.Character
	if character then
		-- Add the item to the player's Backpack
		local backpack = Player:FindFirstChild("Backpack")
		if backpack then
			local itemClone = part:Clone()
			itemClone.Parent = backpack
			warn("successful")
		end
		
		end

		updateInventory(Player)
	end
end

then inside of my itemsinfo script is

local InventoryItem = {}

-- Define your inventory items with categories
InventoryItem.Items = {
	Swords = {
		{
			Name = "Sword",
			Equipable = true,
			Droppable = true,
			Description = "A sharp sword for battle."
		},
		{
			Name = "Axe",
			Equipable = true,
			Droppable = true,
			Description = "A heavy axe for chopping wood."
		},
		{
			Name = "FishingRod",
			Equipable = true,
			Droppable = false,
			Description = "A sharp sword for battle."
		}
	},
	Potions = {
		{
			Name = "Health Potion",
			Equipable = false,
			Droppable = true,
			Description = "Restores health when consumed."
		},
		{
			Name = "Mana Potion",
			Equipable = false,
			Droppable = true,
			Description = "Restores mana when consumed."
		}
	}
}

return InventoryItem

the tool
ScreenShot_20231024111022

error code through my debugging
ScreenShot_20231024111123

1 Like

Hi so i think the issue is that the table you are storing your items in have to be strings
because the category in the tool is also a string

Swords = {
		{
			Name = "Sword",
			Equipable = true,
			Droppable = true,
			Description = "A sharp sword for battle."
		},

should be

["Swords"] = {
		{
			["Name"] = "Sword",
			["Equipable"] = true,
			["Droppable"] = true,
			["Description"] = "A sharp sword for battle."
		},

--plus all the other items

also you dont have to use

local itemInfo = itemsinfo.Items[partcategory] and itemsinfo.Items[partcategory][ItemName]

you can just do this

local itemInfo = itemsinfo.Items[partcategory][ItemName]

im pretty sure that should fix the issue if it doenst please let me know :slight_smile:

2 Likes

didnt work but here is new error code
ScreenShot_20231024183330
it printed the part but not the iteminfo

hmmmm

well i did find 1 thing that could cause this but i dont know for the other items

the category is “Swords” while in the script it is “Sword”

if changing that doesnt work can you print what the item name exactly is

Dude i kept the fishing rod in swords category in the script

1 Like

You should print partCategory, and print the table that should retrieve, then print itemInfo and the table that should receive.

The problem is the arrangement of the items module.
You index partcategory ok, but the table inside each category is arranged by index number.
You will need to specify a key for each (which would match itemname).

swords = {
    Sword = {
        Name = "Sword",
        Description = "sharp pointy thing"
        --etc
    },
    Fishing rod = {
        -- Name, description etc
    }
}
2 Likes

OMG TYSM MAN IM BEHIND SCHEDULE RN AND THIS ERROR MADE ME REAL MAD tysm

This is not true at all, both ways work just as fine.

Also your suggestion:

This will cause the code to error if itemsinfo.Items[partcategory] is nil.

2 Likes

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