How would I give every NPC an "inventory"?

So for the last couple of days, I have been researching and studying how to give the player an inventory.
I think I finally achieved that.

that works + saving (kind off)
The player doesn’t “physically” own anything. It’s all just values, which is loaded when player joins.

But now I need to give every NPC an inventory.
I’m thinking about a module script and a dictionary, but I’m not sure.
Also I’m not really familiar with dictionaries.

My first initial thought, was to give every NPC a folder called 'inventory".
But that seems insecure.

Also, every NPC is unique. They can have the same name, but they’re different.

2 dogs, different inventories
Please don’t mind the laughable dog model, it was my first time.

How would I implement such a thing?
I’m sure I can eventually figure it out, but the code would be so messy and inefficient.
Pretty sure the player’s inventory already took way too much lines.
I know time did lmao (4 days).

I honestly don’t know if I make any sense, it’s super late.

Anyways, thank you for your time.

I Researched about what you want and this is what i found.

Hope it helps…

I’m not sure, but I think that script is adding items to the player inventory. I have no problem with that.
I just need to find a way to create inventories for NPCs.

thanks for your time though

Could you expand a bit more on what you mean? Are you allowing the player to take stuff in the inventory or are you allowing it only to be viewed?

I’m not an expert at data storage but maybe you can try making tables and variables instead of using values, For e.g:

local inventory = {
    Strawberries = 4,
    Logs = 5,
}

and then write the data storage code for it.

My end goal is to allow the player to transfer items to an npc. My only problem is that im struggeling to make an inventory for every single npc in the game.
sort of backpack for npcs.

let me show what I have now.


Oh cool, it picked up my music. Enjoy the bg music lol.

I don’t know if that made it any clearer xd

But, I don’t want to jinx it, but I’m actually getting somewhere.

Yeah, i thought something like that too. But for some reason tables really confuse me xd.

I would say you can make maybe a server sided script assign a value of what objects that NPC has and how much of it and just make it random for each one as it may be very annoying to assign a certain inventory for each NPC if you making a lot of NPCs.

Im not 100% sure what you mean, but every NPC starts with an empty inventory.
The player can just add to it, or take from it.

I don’t know if you ever played Ark…but something like that. you can put items in dino inventory, and take from it. Ofc not as advanced xd.

So how does the NPC get items then?

In that case you can do something like:

Inventory = {
    Strawberries = 0
}
NPCinventory = {
    Strawberries = 6
}
function Switch()
    Inventory.Strawberries = Inventory.Strawberries + NPCinventory.Strawberries
    NPCinventory.Strawberries = NPCinventory.Strawberries - NPCinventory.Strawberries
end

This is intuitive for games with a small amount of values but would be inconvenient for a game which would have 20+ values, Otherwise You would Be getting the table from the player and NPC.