Help with datastores

Hi all, I was working with datastores and I have a updateasync for when the player leaves the game, it is inside of a pcall and if the updateasync fails it will wait 7 seconds then retry again. The only problem I can see with this is what if the player is to relog the game and join another server whilst his data is still being saved. Is there any way for the getasync to wait until we know his data is updated, or will he just lose the most recent save.

well, just kick the player :sweat_smile:

do you have a script?

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

To accomplish this you would need to do what is known as session locking.

1 Like

How about remove the cooldown of 7 seconds and retry instantly? I know DataStores have limits but this shouldn’t cause those limits to be superseded.

You can and should be session-locking as much data as you can. Yielding code in the new place until you are sure their data isn’t loaded elsewhere (saving and kicking from old place).

Additionally, please do not entirely rely on PlayerRemoving if you are. In certain circumstances you will likely run into problems (dev shuts down server manually, last player leaves, etc…). Also handle saves with DataModel:BindToClose (wrapping each save in its own thread).

you can only set data every 6 seconds

alright i will have a look into session locking, ty

if the server is shut down will player removing not work on saving data, if so how will i get that last players data to save

Give a read to this thread:

In very specific circumstances, the listener for PlayerRemoving may not call or finish, and because of that you will see certain data loss. If you are saving on PlayerRemoving and BindToClose you are doing the fundamentals.

You get 60 + total number of players * 10 per minute, as long as you’re not making too many requests for other users you should have leftovers to perform rapid succession requests when a player is leaving.

Does this not apply?

Thank you will look into that as well

Yes it does, ignore my previous efforts. However, I wonder if a failed attempt causes the 6 cooldown to start or if only successful writes do.