Best way to handle DataStore data management?

Hey guys! So I just had a question regarding what is the best way to create DataStore data and stuff like that. (player data.)

To clarify further, I mean like, data you want to give each player that joins in your game. For example, maybe a money value, some items you unlocked, or whatever it might be.

How I used to go about this for a very long time is like this: I would insert tons of instance values inside the player when they would join in the game, and I would edit those values throughout the game. When they would leave, I would use an iterator to iterate through all of those values within the player, then save it to a datastore using SetAsync. I already know that’s taking a big risk, so in more recent years of programming I’ve added some conditional statements to make sure the data has loaded before resetting the async. (if the player joins the game, then leaves before it sets any of the values to the saved data.)

Considering the limitations I have using this method, being unable to manipulate bigger data I need to save. Like, active quests, quest data, and all that kinds of deeper stuff. That’d be extremely hard to create using this older style of data saving I’ve used for awhile. So with that, a new method I came up with is this: I have a module that each player requires when they join in the game, and the module returns the player’s data table. It fires a remote to the server to check/return the player’s previously saved data, then returns that data table to the client. I realize this way of saving/accessing/updating data might be iffy, or hackable, but it sure is a lot easier to manipulate than the other way. So like, I would require the module to return the player’s data, then I would simply update the values in the table returned, then when ever I would need to save that data to DataStores, I would call the save_data() function I’ve created in the module, which handles exactly that.

I’m also required to have the GUI set so it never resets, as that would wreck everything if I haven’t saved the data beforehand.

I just wondered what you guys thought of these methods, specifically the newer method mentioned below. If you guys had any better ways to handle data, please share! I’d love to research/practice new ways of doing this. Also, if you could comment regarding limitations/security of the newer method I’m using that would be great as well.

Thanks guys!

3 Likes

https://www.robloxdev.com/articles/Data-store

Simple Datastore Handler Tutorial

Details on DataStoreService for Advanced Developers

How do I write this DataStore script in the best way?

Methods for Handling DataStore Request

Datastore Organization


What I do is use a Module to store ALL Players Data in a Table with a Script then I make a Table for each player and then send the Data to Client via RemoteEvent to update the Data when needed.

If a Player want’s to buy an Item I use the Script’s Player Data to check if the Player has enough money etc.

Edited

@C_Sharper

9 Likes

Those articles look interesting. Thanks for sharing! :slight_smile:

Thanks for providing me with sample code! That looks like a really nice system. Although I’ve never used metamethods, like, ever. Why do you use them here? Out of mere curiosity.

My DataStore2 module has been used in many games, one with 63 million visits, and other developers like it for its ease of use and reliability.

4 Likes

Because every Player will have the same Data such as Money, Level, EXP, etc.

and these stats will be manipulated, but to make it very easy I use Metatables so I can just call a function on the Data like

PlayersData[plr]:AddEXP(5)

instead of doing

PlayersData[plr].SaveData.EXP[1] = PlayersData[plr].SaveData.EXP[1] + 5

It’s a lot shorter and easy to understand.

and as you can see when adding EXP you’ll need to check if the Player will Level up or not and send Data to the Client.

I just like using Metable and ModuleScripts for organization so I can also forget about the Code that I don’t need to see and scroll pass.

The one thing that you can count on with posts about how to structure datastores is that Kampfkarren will self-promote his Datastore2 system.

5 Likes

Bahaha! Hey man, quality code is quality code that everyone should know about!

2 Likes

I never said that it wasn’t. It’s just something that you can basically count on at this point. :stuck_out_tongue:

1 Like

as long as you know what youre doing, data store errors won’t really be a problem (aside from the fact that data won’t be saved) unless you just blatantly ignore all the information that says you should retry requests and you should check for errors and type x cant be saved. also the limits are pretty large in case youre worried. ive been able to store pixel data for skins in 1 setasync call

Thanks for all the replies, guys!