Datastoring an inventory?

Hello! I’m currently working on a game that involves crafting etc…

I was wondering what you guys think would be the best way to datastore a users inventory. I was thinking about making each slot have a value that would be what item is in it, but I don’t really know if this would be efficient.

7 Likes

There are many different ways you can do this. What I did for an old game of mine was just store the kind of item that player had in a table and save the table with DataStore.

There are probably more efficient methods out there but this is rather simple and it’s something you might be able to build upon.

13 Likes

I usually just store a table of the items that the player owns.

For example, if the player owns a diamond sword and a steel axe, I would store it like this in the datastore:

UserData={
  ["OwnedItems"]={"Diamond Sword","Steel Axe","etc"}
}
12 Likes

Both of these methods makes sense, use tables to save a users inventory! Thank you both very much.

3 Likes

As an afterthought, over time a users inventory table can get pretty big. In order to save space, you might want to compress user data before saving it to the datastores, and uncompress it when retrieving it from the datastores.

1 Like

I personally use this:


It might seem complicated but it really isn’t. I’m just saving the Item by adding line between name and value and when I load it I just find that line in string. left side of the line is a name right side is a value

5 Likes

How can you do this?

1 Like

This tutorial should be of use. :slight_smile:

4 Likes

Why use this over traditional dictionary/key tables? It seems a bit overcomplicated.

2 Likes

Thank you!

2 Likes

He’s saving different information about a single item in one index of a table, I imagine this helps with space when storing a lot of information.

1 Like

But that single table index now uses double the data, resulting in roughly the same amount of data usage as a key table.

5 Likes

Gah, you’re right. Now that I think about it, it’s probably just his prefered method of organizing the stored data.

2 Likes

When I first started learning datastores. There were some stuff I couldn’t understand so I came up with that method and using it even now. It does all I need so I didn’t really need to switch to something new.

1 Like

Don’t worry about it. We all have our own methods and quirks for the code in our systems. :slight_smile:

2 Likes

I used a table just like @Reshiram110 said. Works really well and I can save up to 4,000 items (nobody made it past 200 lol)

5 Likes