Is my inventory system problemtic?

I made a dictionary that stores all the player’s data through IDs and then gathers the data of the items through a Database (ModuleScripts, folders, etc.) in ServerStorage (models for swords, images, stats, etc.) and I realized that it feels kind of inefficient and long. Here’s a look at the dictionary:

local plrTable = { -- get data from database through IDs
    ["itemInventory"] = {
	    ["slot01"] = {
			    ["ID"] = nil},
		["slot02"] = {
			    ["ID"] = nil},
		["slot03"] = {
			    ["ID"] = nil},
		["slot04"] = {
			    ["ID"] = nil},
		["slot05"] = {
			    ["ID"] = nil},
		["slot06"] = {
			    ["ID"] = nil},
		["slot07"] = {
			    ["ID"] = nil},
		["slot08"] = {
			    ["ID"] = nil},
		["slot09"] = {
			    ["ID"] = nil},
		["slot10"] = {
			    ["ID"] = nil},
		["slot11"] = {
			    ["ID"] = nil},
		["slot12"] = {
			    ["ID"] = nil},
		["slot13"] = {
			    ["ID"] = nil},
		["slot14"] = {
			    ["ID"] = nil},
		["slot15"] = {
			    ["ID"] = nil},
		["slot16"] = {
			    ["ID"] = nil},
		["slot17"] = {
			    ["ID"] = nil},
		["slot18"] = {
			    ["ID"] = nil},
	    },
	["defenseInventory"] = {
		["hat"] = {
			["ID"] = nil},
		["torso"] = {
			["ID"] = nil},
		["leggings"] = {
			["ID"] = nil},
		["sword"] = {
			["ID"] = nil}
	    },
	["currencyValue"] = {
		["Gold"] = 0,
		["Gems"] = 0,
		["XP"] = 0
	},
	["powerCards"] = {
		["slot01"] = {
			    ["ID"] = nil},
		["slot02"] = {
			    ["ID"] = nil},
		["slot03"] = {
			    ["ID"] = nil},
		["slot04"] = {
			    ["ID"] = nil},
		["slot05"] = {
			    ["ID"] = nil}
	},
	["boosterCoin"] = {
		["ID"] = nil,
		["timeActivated"] = nil -- unix time
	},
	["Perfume"] = {
		["ID"] = nil,
		["timeActivated"] = nil -- unix time
	}
}

Please do note that I’ll be adding more data to this as I develop my game. Is this inefficient and will this cause a lot of problems (e.g taking too long to load, delays)

TL:DR: I store playerdata thru ids then get the data in serverscript. will this cause any probs?

1 Like

Organize it however you like. Won’t run into any issues with data loading too slowly.
About the slots though, maybe only save the slots that are being used. Can have a variable called MAX_SLOTS if you want to have a certain amount of slots.

2 Likes

I’m actually kind of copying Minecraft’s slot system where you can move items around the hotbar/backpack however you like. I guess I could simply do this:

["itemInventory"] = {
    [insert itemID] = {
        ["slotNum"] = nil},

and when another item is added, I simply insert another dictionary. Would that work?

1 Like

that might make searching difficult when you want to figure out what item is in slot number ___ because you’d have to go through each item and look at what slot number they’re in.

what I meant by only saving the slots that are in use is something like this:

if I wanted to put 15 dirt blocks in slot 5 I would say something like:

itemInventory[5] = {ItemName = “DirtBlock”, Amount = 15}

if I wanted to clear slot 5 I would say:

itemInventory[5] = nil

1 Like

Oh that makes sense. Thanks a lot!

1 Like

yeah, np. pm me if you have any more questions!!

1 Like