Inventory Datastore Help

Hello devs! I’m working on a RPG game and would like to make a Datastore for the inventory to save.

Since I don’t know the datastore very well even in my 2 years of scripting I tried watching videos or searching in the Forum but I can’t find any working script.
If anyone knows a working inventory model or script that I could use please let me know I’ll just have to edit it.

Thank you! If you have any questions please let me know.

Are you struggling with making the inventory script, saving it to a datastore, or both?

I’d say both. But the most difficult for me is currently the datastore.

What i do to save inventory and amount of items is just using a simple StringValue. After that, to count how much of each items, just count occurence (Which could be easly found on google)

Well, your inventory system data will probably resemble some sort of 2d array.

You can directly save this array to the datastore depending on how you’re storing the data.

I would suggest starting with the actual inventory system, and then worrying about how to save it. Its hard to save a data structure when you don’t know how its going to be formatted.

1 Like

I tried but maybe I did it wrong. Can you show me and exemple? Else like you said I will search on google. And thanks for the reply!

Here is what i use (i also found it on google):

local function OccurrenceCount(Pattern, String)
	return select(2, Pattern:gsub(String, ""))
end

you just need to put the Pattern, the string you want to know the amount and that’s all.
For example if you have “BananaBananaAppleIron” and you want to know Banana, you just have to do:

local amount = OccurrenceCount("BananaBananaAppleIron", "Banana)

and it should return 2 since the word Banana is there twice

Im not sure why it would be good to store your data like that. Arrays are much neater and roblox provides built in functions for us. Look into 2d arrays, the link i provided above has examples.

Yes thanks I looked but I am not experienced enough to use this sadly.

Because this way you dont need thousand datas, just one data for all items. But of course, if you need statistics to your items, you cannot do that

This is illogical. Using an array is not having “thousand datas”. It just a more organized way to store multiple values. I understand you’re trying to help, but please don’t speak on threads if you don’t know what you’re talking about. Giving bad advice not only hinders his ability to accomplish his goal, but now everyone else who looks back at this in the future has to read through inaccurate advice.

i’d say it would be easier for you to use loleris’s ProfileService if you stuggle with regular datastores

Alright I found a way to save tools. it’s a bit poor but it’s working! Thank you!

1 Like

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