Undupable trading system with DataStore2?

I’m working on a trading system for my game and I want to make sure dupes aren’t possible, as I heard that was a common issue when creating trading systems with DataStore2.

I’m concerned about some specific edge cases: (Tell me if I am missing any that would be of concern)

  • Two players trading, then one leaves right before saving
  • Game crashes or shuts down mid-trade
  • Exploiting via lag-switching or disconnecting at the right moment

I’m looking for advice or examples on how to structure a safe, atomic trade between two players. Specifically:

  • Should I lock both players’ inventories during a trade?
  • Is it safe to make temporary changes in memory and only save after confirmation?
  • How can I use DataStore2 in a way that makes sure the trade either fully succeeds or doesn’t happen at all?

If anyone has implemented this successfully or has best practices, I’d really appreciate some guidance.

Thanks!

1 Like

Consider using ProfileStore or implement session locking yourself.
Literally most of the time dupes happen because of lack of the session control.

3 Likes