Should I use UpdateAsync() or IncrementAsync?

So UpdateAsync is superior to SetAsync (in a lot of cases, not always), but what about IncrementAsync?
The good thing about UpdateAsync, is that it considers the old value, if I have 100 coins and want to add 20, instead of overwriting it with 120, it will add 20 to the 100. Isn’t that exactly what IncrementAsync does? Should I use IncrementAsync in this case?

1 Like

I believe IncrementAsync should only be used for variables that intend to only ever go up. With coins, a player could simply buy the most expensive item in the game, leave and still have all their coins because you’re not taking away those coins. Arguably you could use negative values but that’d just cause unforeseeable altercations.

I’d recommend just using UpdateAsync or another framework such as profileService.

It really depends on what you’re doing, personally UpdateAsync is overall better, as it returns the old data (if any), which can be used to compare the new data.

To answer your question: It doesn’t matter, but I’d choose UpdateAsync over IncrementAsync as that’s just my preference.

ProfileService is mainly used if you have a trading system in your game, as it has session locking.
In short, you won’t end up with duplicate items.

@Benified4Life @Xysteric
Thanks both, I’ll keep using UpdateAsync :slight_smile:

1 Like

ProfileService is just useful in general? I know a lot of people who use it over making their own data system because why would you re-invent the wheel.

Apparently, ProfileService is a bit slower than regular datastores (when loading data), from my experience (and others).

It was mainly implemented due to session locking.

Why would you benchmark a Data store library/module vs a raw Data store?
ProfileService has so much more than just :UpdateAsync and :GetAsync than a regular datastore. Of course it would be slower, why does this matter?

Should I be saving my data 0.01 seconds faster than a module that does the same thing?

Why would you benchmark a Data store library/module vs a raw Data store?

I didn’t, other players did.

What I’m saying is there’s not really any reason to use it if you don’t have a trading system.
DataStore2 is a safer approach, even regular datastores.

Just because of session locking?
Session locking doesn’t make it different from other datastores, it’s still a datastore like DS2.

And DS2 isn’t safer since players are able to duplicate data. ProfileService stops that by using session-locking.

And DS2 isn’t safer since players are able to duplicate data.

I have yet to see this, at least back up your claim with evidence?

Anyways, this is off-topic, let’s just leave it.

All the proof you need, Dungeon Quest used to use Datastore2 before they stopped because of this.

Edit:
Revoked the video to show more videos.

Anyways, sure, it really is off-topic.