Fully saving character custmization and inventory system with Datastore 2 module

Hello! So I was just curious what the best way to script a system that saves the players character customizations. Previously, I created int values for each character preference I wanted to save. E.g, Hairtype = 1, Skincolour = 3. Anyways, you get the idea. After those values were saved under those keys, I would then whenever the player joined check each value and apply what they had on. Now, I am wondering if thats usually how other people do it or no? Is there a more efficient way on scripting this? Secondly, For inventory systems I just did the same thing. I create int values called like longsword = 3, and check it and then put 3 longswords into there inventory gui container. Again, what would be the best way of doing all this? Also, the code required for my method is sooo many lines and its just painful. Also if i wanted to save what armour they had on or what items they had in there hotkey bar ect. I just want the current project That I am working on to have efficient and good solid code.

As for me I doing inventories like that: giving player an empty array and add new elements for each item player aqquire, but I’d use different system for a character customisation, I’d put avery characteristic of appearence into array and give it specified value, I guess it’s the same thing you done, but here is example:

{Hair = “Long wavy”; HairColor = Color3.new(1,1,1); etc}

However it all depends on your game and when one can be for example about farming much of same loot and storing it in inventory in stacks it may be useful to use system that stores amough, but other may be an survival where any item may need to have bunch of stats, as most common is durability, but there is much more, so this system is more elastic and may be used in any project

well, i was also wondering like what if i were to store all the values in a table and then save them to datastore2? But how would i save an array with ds2 and can i even add the datastore values to that table?

You can, ofcourse, save whole array in datastore2 module, but why you may want to do so? It’s designed to save anly needed items, so you just dont need any arrays if you are making a customisation saving. But yes, if you need an inventory system I didnt find a good way to just add items like you do in other cases with datastore2 and just using array to save inventory.

it would be much more efficient than saving individual values. Less code

1 Like

It’s literally several characters per change, dont think it’s making your code much bigger, but on other hand it makes you to more comfortably navigate datastore, like instread of

casharray["Hairs"] = 4
savefunction()--5+ lines without any backups just with pcall() wrap

you use this

cashstore:Set(4)

But if we are talking about effictivity it’s not right to count only lines of code, it’s about readability and optimisation and when you create in server side’s (roblox stores) array another one only to write all your values in it just to make your code be smaller it’s basical example of unoptimisation. Not so critical and I’m not the one who can say “you are writing your code wrong” but in my opinion it’s makes less sence then it doesnt. It’s about saving server time for doing something more important, ofcourse not a critical change and you still can use without harm to your game.

so i should just do it how i have been doing it?I dont think you understand how much code it is. Here is a pastebin with my code local DataStore2 = require(game.ServerScriptService.MainModule)DataStore2.Co - Pastebin.com

1 Like

I said before that I’m not the person that can say that your code is wrong, but I for sure cant say that your code is right. You can just assign a color3 value into datastore to save color and use for loop to color all body parts in it, instread you manually set color of every bodypart and it’s just most common example I found out there, with the same succes you can change meshes of everybodypart saved to a asset id you saved in datastore using for loop, so I guess you need to learn a little more to optimise your code, so you dont have to wrtite 10k lines to save 10 characters.

Exactly, which is why I made this post lol