Few Questions on dataStore

I Had a few questions about data store

How reliable is storing data on PlayerRemoving. My game needs to save data quite frequently cause it saves a lot of different things. But everything is in one large dictionary. So I’ve just created a copy of the dictionary from GetAsync. and whenever something is changed I just update the copy of the dictionary and then SetAsync it. (Its a single player game so i feel SetAsync is more appropriate than UpdateAsync).

My question is should i be SetAsyncing this dictionary every time its updated and risk the final saves not saving because of the length of the queue. Or save it like every 6 seconds (I believe this is how long your allowed to save between to prevent queueing ) and have a player removing event that saves whatever the copy of the dictionary is current.

Also can the server shutdown before my player removing event function can finish?

(I apologise i have never really used data storage I’m just basing everything off the Roblox wiki page for it)

1 Like

Was concerned about how frequently you planned to use Setaysnc but seeing that its a single player you should just stick with intervals of 6 seconds (If its the same key). You will only have 70 per minute as your SetRequest Budget. Thats plenty if you don’t plan on having like multiple keys/datastores.

The resource I sent above should solve this problem aswell. In the case PlayerRemoving isn’t even called. There are cases . but that’s why we use to prevent those cases from effecting saving data game:BindToClose

1 Like

SetAsync is never more appropriate than UpdateAsync, has nothing to do with single or multi player.

You should never save based on an action (table updates, player dies) as that can happen many times quickly and overflow the queue.

You should for multiple reasons always have a cache and save periodically.

  1. you’ll never run into request overflow and potential data loss
  2. if you use getasync when you want a value you can run into serious race condition bugs, that can be exploited (e.g. duplicating items)

I’m not sure what the copy is about you don’t need a copy, just use the table GetAsync returns

You use game:BindToClose, to run code before the server shuts down


personal recommendation

I use and recommend other people use ProfileService by loleris, it’s an extremely robust, nice abstraction for storing data, has full support from loleris (constantly being updated), easy solves things like race conditions because it’s session locked. I think most pros use it.

2 Likes

Okay thanks guys I appreciate the help