I recently encountered a problem. I started using one big script to make a game, and now I have a lot of leaderstats and playerstats (different folders a few private stats), and made a datastore. At first I thought it would be simple to just make another script and make my code more readable. WRONG, some reason I cannot access datastores with out flagging the limit and throttling my game. I do not know of any other way to access a datastore besides GetAsync() and SetAsync(). So when I call them in another script the game starts to have huge problems. Because sometimes I want a heartbeat to be triggered every 10 or 15 seconds. When you get 15 stats going and some might change every hour some change every minute and it starts causing issues. After researching this problem a lot of people from what I see just switched over to Profile Service. Is that what I should do? Also, my code works fine in one big script but its ugly and I don’t like it. I have zero issues in 1 script because everything is together, and the GetAsync and SetAsync are called once, also when player leaves. I started reading about this in the forums but am not sure. Maybe it is my coding knowledge that is hindering me and not the database saving method that isn’t the problem. One example is that if I have chickens that lay eggs every 15 seconds or 20 seconds I can make that work in my main script, but if I want to separate the scripts into one that is for “AnimalProduction” when I access the data with a GetAsync, and SetAsync to put the data back into the datastore my game goes ballistic with the data limits. Works fine in main script… Maybe someone can help guide me.
As for reference the post I read. My guess is it is just time to move to ProfileService?
How can I access a datastore and set the data back into it with DataStoreService, with out hitting limits?
I am starting to wonder if it is my fault as I can’t seem to get the data to update with out using GetAsync() and SetAsync()
All ProfileService is, is just Normal DataStoreService, It was Designed to help Prevent Data Loss, which means to Handle the Data Efficiently, Normal Data Loss Happens when it is not Handled Properly, and the Queue means you are Sending too many Requests at a Time for someone.
Its never a Good Idea to send Multiple Requests for one Player, If you have Mutliple Keys for one Player Containing a Single Piece of Data, that would be Bad Practice. What you should be doing is putting them together inside a table, when you do this, you can essentially put it under one key, and just save the Data like that, and you can access all of it, when you need it.
As for your Gameplay, I recommend you just Update the Session Data (as in you place the new Data inside the Players Current Session Data, but do not Save it), and then when the Player leaves, you Save the Data, AutoSave every couple of Minutes, and if it doesnt Save Properly, you use game:BindToClose, BindToClose will fire code when the Server is closing, but there is a couple of things to note when talking about BindToClose:
Real Servers
When BindToClose is fired on a Real Server, there will be about a 30 Second wait, which is enough time to use BindToClose, In Studio, you do not have this feature, instead what BindToClose will do, is fire, then immediatley close, which is why you usually see a delay when closing the game.
Not Always Perfect
Just because you use BindToClose, It doesnt mean it will Save 100% of the Time, There are times that it will fail, and that is just normal.
If you really want to, you can Design your Own DataStore Module, so you can Handle your Data. ProfileService is just a Community Resource that you are allowed to use, but it doesnt mean thats a Completely Different thing, its the exact same concept, just Different Managment.