I am currently working on a little something in my spare time and it involves stats, inventories, customization, etc. Basically, there are a lot of unique things I need to save via datastore for each individual player.
Not really a problem, I have my own method of doing that that looks a little something like this:
Stats/inventories are located in the player object inside of a folder named “whatever I need it to be named.”
Stats and inventories are the appropriate type of values. String values with JSON tables in them for inventories, number values for stats, boolean values for other things, etc.
Upon leaving, I consolidate all the stats into a single JSON and save that to the datastore.
When the player enters, the saved JSON is decoded and the appropriate values are set.
My questions is this:
Is this the best/easiest/most efficient way of doing this? My hunch says no.
I would personally use an External DB that is on a site (self hostable), Which means then it wouldnt Corrupt as much as Roblox’s Datastore, But Everyone has Opinions, I just prefer External Databases. (There is many Free ones like my Favourite Enmap.) But Enmap can work with node.js , But theres many.
EDIT: Enmap saves it as JSON, Which is easy to access, For example I use it for my Service to Check if they are Blacklisted via the port, E.G: /db/fetch/:USERID would return it as JSON,
Im not so much concerned with the PLACE the data is saved, more of the method of saving it. If this project is ever completed and gets a good following ill probably end up using something external anyway.
I may be incorrect, but I don’t believe encoding data into JSON before saving does anything to help space. I think it is encoded to JSON by Roblox when it is saved into the Datastore.
The method of saving it seems to be fairly universal from what I’m reading here. Whether you JSONEncode it or not, DataStores will automatically JSONEncode it.
However, you could try using UpdateAsync periodically while the game is running to further ensure that data isn’t lost.
Yea they will be turned into JSON when they go into the Roblox Datastore. This is an example of how I set some of my data up.
local function returnNewCharacterEntry(character)
local characterInfo = CharacterService.getCharacterInfo(character)
return {level = 1,
exp = 0,
currentHealth = characterInfo.health or 100,
health = characterInfo.health or 100,
attack_speed = characterInfo.attack_speed or 1,
power = characterInfo.power or 1,
walkspeed = characterInfo.walkspeed or 20}
end
This will all be encoded to JSON when I save it, and decoded when I retrieve it. They are all saved under one key which uses the player’s userid + some other random strings.
Since it is encoded to JSON it can only use primitive values such as numbers, strings, and tables. When I get this table back I will be able to access the values like so…
local data = Datastore:GetAsync(key)
print(data.beta) -- will print true/false