Stop using SetAsync() to save player data

UpdateAsync is absolutely important to use in real time systems and should not be dismissed for SetAsync. ProfileService is a good example of a rising library that works with DataStores. It takes advantage of the fact that UpdateAsync is both a getter and a setter to perform some of its internal work, especially with regards to locking data to sessions.

Adding or removing members to a clan would be a matter of adding or removing someone from a collection, so it’s held in the same vein as incrementing and decrementing data: UpdateAsync is good to use here so that you’re actually mutating the data. SetAsync is candidate for failure in this workflow because you now have to account for other servers and determine which holds the true value for the DataStore. Determining this point of truth can be extremely tedious.

SetAsync is not a better choice for player data and UpdateAsync would be equally as bad if you use it like SetAsync. Use UpdateAsync for what it’s good for, which is more than just overwriting values. It allows you to modify and update it, as its name suggests.

7 Likes