Same as saving any other value.
I think I found a solution, and no reports of data loss. What I did was when a player joins a new game, the data waits for 5 seconds before grabbing it to make sure the previous instance of their data has been removed.
What’s the function of manually saving every 60 seconds? I’m only aware of the standard :Set and :Get stuff. Plus, I thought it saves when data is changed? But of course that’s not the case in my situation.
I just set a loop to save everything every 60 seconds in a different thread, like this -
coroutine.resume(coroutine.create(function()
while wait(60) do
-- save data here
end
end))
Why don’t you just use coroutine.wrap(function)()
instead of using coroutine.resume(coroutine.create(function))
?
Because they both are essentially the same performance-wise.
Sorry I’m not catching quite on, I understand the loop part, but I thought using :Set when setting the data saves it? Is there some kind of :Save function that I’m missing?
If you set the data, it will save automatically.
Just save the data as you would normally, but on a 60 second loop.
So just :Get the data and then :Set/:Increment it every 60 seconds?
That’s pretty much about it, but remember to save the player’s new data, not the retrieved data.
Why would you do this? Doesn’t DataStore2 just save a player’s data when they leave? Is there a way that saving can go wrong?
Is there a way to change the data of a player who is not in game? For example if I wanted to wipe an exploiter from a leaderboard?
For some reason, I’m not too sure, I’m getting quite a few instances of dataloss, not all the time so I know what I’m doing is relatively correct. But I often get reports of a single bit of data being lost.
I iterate through a table of default data and call:
local dStore = DataStore(DataName, Plr)
With DataName being the index/key of the default data.
Am I doing something wrong here?
To expand on this, it usually seems to be a full sessions data. Any help would be appreciated
im experiencing this too, still dont know how to fix it ):
Of course it can, datastores normally can save bool values.
What would happen if the player lost connection? The player would just disconnect and the server wouldn’t be able to save their data. Autosaving prevents some data loss so that the player wont have to start over completely if they disconnect.
Correct me if I’m wrong, but isn’t the data saved on the server everytime it is changed. So the server has a local cache that it writes to the DataStore only once? (when the player leaves)
I don’t know how DS2 works, but if you saved the player’s data every time it changed, the datastore limit would be reached EXTREMELY quickly.
Exploiters could even intentionally write scripts to rapidly change their data and cause your datastore script to slow down or even freeze up.
Autosave circumvents this and prevents data loss at the same time.
As I said in my reply the way I think DataStore2 works is that it keeps a “local” cache of every player’s data in that server. When a player leaves it saves that player’s data only once to the DataStore.