What should I actually do with a table of data when I get it from the Datastore?

I currently have a data system that works, but I don’t know if it’s the best way to do it.
image
Is it bad to get a table of data from a datastore and then make it into a bunch of Values to put into the Player like this?

I don’t see why you would when you can catagorize whatever piece of data you need though the scope (in the second parameter of GetDataStore())…

Is there a specific reason you need Value objects inside of the Player?

My suggestion is to store data values with a scope. You can do so with GetDataStore(name, scope)
Whenever you do this, every piece of data stored in DataStore “name” will be under the scope “scope” whenever an operation is done using the DataStore. This isn’t to say that the DataStore can only add/remove/modify data under that scope, you can create another instance of the same DataStore but under a different scope.

Those are my thoughts :slightly_smiling_face:

There is no specific reason I need value objects in the Player. It’s just the only way I could think on how to even make it work. I’ll take a look at scopes and see exactly how they work and see what I can and can’t do with them.

There’s some information about scopes in this article, though I’m sure you’re already found it
Data Stores (roblox.com)

One more thing I want to mention, keep as much data on the server as you can. Exploiters are able to see everything on the client, and if you store stuff on the client, the exploiter can read/(likely modify)/remove it.

I pull all datastore requests into one script. I start with defining an empty table:

local statusData = {}

Then I pull the DataStore2 table into that table:

statusData[player] = tablenamehere

The contents of the tables are sent to scripts that need them, manipulated and returned. Then, whenever I update the contents of tablename here, I save it.

1 Like

So this is what I think you are trying to say:

  • You have one table called statusData in a script on the server.
  • You get a player’s data (which is just a table) and place the entire table as a key in that one table in the server script
  • You send a player’s table by using statusData[player] to a different script so it can change
  • That different script changes the values and sends the table back to the script with the statusData table
  • You replace statusData[player] with the table the different script just returned

Is this the best way to do it or just something you made up that just works?

I’m still looking into scopes by the way and they are seeming rather promising.

I don’t know best ways, lol, but I am trying to be consistent. If I need to fix save files, I want them all in one place. If I’m fixing combat, I need to be in my combat script.

I will say it’s pretty efficient.

I believe I found what I need.

And, Gloji, if you used a ModuleScript for your method, it would’ve been nice if you just said so. I also should’ve asked, but for some reason I just automatically assumed you were using a normal server Script and I didn’t even think to question my assumption.

Also, thank you Vii for mentioning Scopes. I’m not sure if I’ll use them or if they are even useable for this ModuleScript method.

I did not use a module script. I don’t like module scripts except for event handling, and have been working to remove them from my game. I use a bindable function to pass information between server scripts. I was explaining my method from memory without access to my scripts, so it was a bit vague. Sorry about that.

Many people prefer module scripts, which is fine, but I like more strict control over the communication between my scripts. :slight_smile: