How do i prevent duplication of ingame items/currency and dataloss?

it would be cool if anyone could explain me how to make a really secure datastore that always saves your data independant of what the player does or roblox

and no weird things happen like duplication or data loss

some code examples would be cool too

btw i like to store alot of stats in data (string values, number values, int values, etc.)

The idea behind preventing duplication and/or data loss between sessions is typically called “session locking”. Session locking involves securing a token that when obtained signifies the ability to securely perform an action or actions that could otherwise be insecure.

One way to think about session locking is like an elementary/primary school hall pass:

  • A single hall pass exists, hanging on a hook by the classroom door
  • When a student needs to leave the classroom, they take the hall pass with them as they leave
  • When that student returns to the classroom, they return the hall pass to the hook by the door
  • No student is allowed to leave the classroom without the hall pass

ProfileStore is an open-sourced example of a DataStore wrapper that implements session-locking. It takes advantage of the GlobalDataStore:UpdateAsync() method, which “reads before it writes”. I’m no expert on the inner workings of ProfileStore, but essentially it secures a token (hall pass) signifying that the current session (student aka a Roblox server) is allowed to safely write to a DataStore. It achieves this by claiming the token when reading a DataStore when the client of interest joins a server, holding the token until the client of interest leaves (and any necessary write actions are resolved), and also by ensuring no other session has a more current token when writing to a DataStore.

2 Likes

thank you, i will try profile store

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.