DataStore saving issues with TeleportService

Allow me to preface this by saying, this is an already existing game of mine, so I can not change to ProfileService or DataStore2 completely because this would cause players to lose data.

My main issue is that when players use TeleportService and are teleported to another world for something, their stats are reset. Here are the events that cause Data to be saved. I use the built in DataStore service for all of this.

  1. Data is saved every 60 seconds from a forever loop.

  2. Data is saved upon the PlayerRemoving event firing

  3. Data is saved upon the game closing

  4. Data is saved when the player is being teleported from server to server.

However, when ever the player teleports to different servers, they data does a reset back to the previous version. This signals to me that their Data has Saved, but it has not yet overwritten the previous Data. Sometimes it saves, sometimes it doesn’t.

What could be some solutions to fix this?

When you say different server do you mean a whole new game or just another server of the sake game?

Another server of the same game.

Like, place, or server? Just double checking.

So the game branches of with the starter place and has sub places, the Player is transferred from different places, to different places with in the same game. However, the player can also switch servers with in the same place.

The issue is the Data is not saving fast enough, and I am trying to come up with a fix.

Maybe add a delay in the teleport while it saves. Once it saves, teleport them.

1 Like

With DataStores there is a Write time(basically a delay before you can access the new data)
Its about 6 seconds
So your problem might be coming from the fact that the DataStore just hasn’t updated yet try adding a delay to your teleport

1 Like

You can probably cut the fourth one out, that’ll throttle. PlayerRemoving fires for players that successfully teleport out of the current instance, so in that case you would be saving twice: once when the player starts a teleport and another when their client begins refreshing the DataModel and loading in another place. Shouldn’t affect you though, at least one of those save attempts should go through.

Have you been able to diagnose at all when this occurs? Try keeping an eye on the console and have someone teleport in such a way that causes data loss. Observe what happens, if anything at all - errors, warnings and queues. If none of that is happening, you may want to revisit your implementation and see if it’s prone to overstepping the limitations set for DataStores. I don’t know how you handle them, only the scenarios in which you save data from.

Nothing is wrong with the Data system itself, their data is just being loaded before it has finished writing internally. It only happens from server to server teleports.

The data in the game can change significantly over a 60 second time period, and sometimes Players will only be in servers for 30 or 40 seconds. So the Data has to save just before a teleport.

There is a 15 second delay between saving and teleporting, and it still occurs in some cases.

How do you know for a fact that there isn’t something wrong in your implementation and that the data is simply not saved before it’s fetched? What tests have you run or observations have you gathered? A cursory glance isn’t enough to properly understand what’s going on.

We’ve done print tests, we used GetAsync() to get the players most recent save, and then they took a screenshot of their data and stats right after they joined and they matched.

I would stay in the original server that a player was teleporting from, to read the previous data. And the saves completed successfully, and the loads in their server completed successfully (else they would have a data reset).

This also does not happen when a player simply leaves a server and joins later, it is only when switching servers.

Essentially, if a player joined a boss-fight server and defeated the boss their stats would be saved via the server, however, when they join the new server, their stats are the same as when they joined the boss-fight in the first place.

This is currently what happens before a teleport, if the data successfully saves, loop is broken, the game waits 10 seconds, then sends the Player to their destination.

There is a debounce system in the Statistics Handler that checks for throttle requests and retries the save 7 seconds later if a request will be throttled, or it fails.

Hey! I humbly ask, have you found a fix to this?

Did you mean, place or server? I didn’t understand what you said, what you said give the impression that it is the game server

has anyone figured this out? switching to datastore2 isnt exactly an option for me…