Datastores problem

I made a game. Player stats are saved every 10 seconds.
but when there are more than 10 players this warning appears all the time

How I can avoid this?

1 Like

You’re sending requests too quickly, well, maybe not but it’s a warning.

Like it says, try to have an autosave function to save their stuff whenever it changes and a save function when they leave.

This may mean there are too many requests being sent to the DataStoreService at once, the request is added to the queue and will eventually be saved to the DataStoreService.

To avoid this, you can instead use an event to save player data when the player is leaving the game.

The function looks like this:

game.Players.PlayerRemoving:Connect(function(player)
print("the player named "..player.Name.." has left the game!")
end)

when a server is closing, it may not save anything to the DataStoreService in time.
the BindToClose function can stop the server from fully closing, giving the script a chance to save data.

game:BindToClose(function()
wait(5)
end)

Saving everytime a value changes can cause the developer to reach the DataStore limit excessively quick. It is recommended that you only save under these circumstances:

  • Player is leaving the game

  • BindToClose (game is shutting down)

  • A user purchases a developer product

  • Autosaving every 120-300 seconds.

2 Likes

The DataStore request limits can be found here. Make sure you plan accordingly (saving every 10 seconds is probably overkill, save on important times and less frequently just based on a timer).

1 Like

I use DS2 so that’s not really an existent problem for me.

DataStore2 has limitations, such as OrderedDataStores. Creating and using your own DataStore system effectively can have better results relative to what you’re attempting to accomplish.

Isn’t it dangerous to save the data only when the player leaves the game?

It can be, that is why I recommend having an auto-save feature, which would periodically save a player’s data every few minutes.

Ahh, yeah. Agreeable, I appreciate it.

1 Like

I can’t save the data when the player makes a purchase. It only gives me worse results

Does this mean it is bad to shutdown servers when there are many players?

Normally, when there is about one player left in a server and that single player leaves, the server may shutdown before the script can save all player data to the DataStoreService, the :BindToClose function can keep a server running for a period of time of your choosing, giving the script time to save data to the DataStoreService.

So, if I shutdown the servers when there are many players, there won’t be enough time to save all players data

Using BindToClose I doubt it would be an issue, server crash could still lose the data. So you should still have some (just not as frequent) auto-save in combination with big changes in data. Just make sure you’re within the limits.

Depending on time length, there may not be enough time to save all player data if a server is being shutdown with a higher amount of players.

Using multiple ways could make this more safe.

I recommend using a :BindToClose function that will wait at least 17 seconds with a .PlayerRemoving event to double check before a player leaves the game.

but as well as an auto-save feature in-game, it would be well to work with the other methods,
saving this data every couple of minutes I would recommend.

you can also try the .Changed event if the player data is in a folder.
Every time the value is changed, It could save the new data to DataStoreService, but I mostly recommend the previous methods.

1 Like

You should not ever be doing this. The only time that pushing updates to a data manager is acceptable if if you have a session data module which tracks player data. Pushing data to DataStoreService each time a change is made is a speed run to exhausting your request budget.

1 Like

Just to let you know, this error could also be showing due to players leaving within 6 seconds of the auto-save of their data. This would mean that the “6 seconds between write requests” limitation would have been met, which throws this warning.

This warning doesn’t make it clear which limit has been hit, and has confused me in the past. You could ignore it, or you could create a table of values containing when the last save of each key was and make sure that the time since then is at least 6 seconds before saving, or waiting until it’s been at least 6 seconds since the last save.

Due to you saving every 10 seconds, I can see this error likely to show when players leave as there’s a much higher chance of them leaving within 6 seconds of an auto-save.

1 Like