Saving data frequently with Datastore2

I wonder if i can save data frequently to datastore, is this even possible with datastore2?

My solution so far :

  1. Save the data every 5 seconds/more
  2. Save the data with PlayerRemoving event

I’ll appreciate every response

1 Like

I personally with DataStore2 is save upon the player leaving.

2 Likes

From Gotchas - DataStore2

The normal way of doing data stores is to keep a cache somewhere of a player’s data (such as in a folder or using leaderstats), then saving when the player leaves. It is wrong, however, to use DataStore2 this way . DataStore2 is built to be used whenever your data actually changes. You shouldn’t invoke DataStore2 in PlayerRemoving at all . Don’t worry, :Set will never error or do API calls, it’s all cached. DataStore2 will save the player’s data before they leave.

In short, don’t manually do anything on PlayerRemoving, because DataStore2 is already automatically doing it for you.

4 Likes

ok, but is it safe to save data like 10 increments per second?

1 Like

Do you mean change the cached data by calling Set, or pushing the cached data to DataStores by calling Save? The former is totally fine, that’s one of the great appeals of DataStore2. The former will not work. You’ll hit rate limits real fast.

ahh i see, so basically :Increment() will cache my data and not saving it to roblox before :Save() is called right?

yeah increment() and set() cache data, datastore2 saves by itself automatically you just need to update its cache

1 Like

ohhh ok thankyou for your reply!