So when you win the game, the player gets their winstreak up by 1, and an extra win. The game is in a place in the main game. And the lobby is the spawn place. When the game ends and you get sent back to the lobby, the data doesn’t save and it goes back to what it was before. The code works, everything works. I even changed the data in the lobby, rejoined and it saved. I don’t know what is happening.
Thanks for reading, this is really important to me since its the literal last thing I need to publish my game, and I need the game to be published by December 20th.
I believe what is happening is that your data is saving, the player is teleported, the player’s data is fetched in the lobby, then the data finishes saving. This means your lobby gets the old data, then the new data is added to DS, but then your lobby writes over that data.
I did some research and all I could find was another unsolved topic about the same problem (don’t use TeleportOptions btw, they’re client sided).
I don’t have experience with trying to save data right as a player is being moved to a different server, but here is what I think might work:
Create 1-2 datastore keys for each player
The first key is data that gets change in the game place
The second optional key is data that gets changed in the lobby place
Then what you would do is on the game server, you’d get the game data and the lobby data, but then only save the game data (because you don’t change the lobby data). On the lobby server, you again get both the game data and the lobby data but then only save the lobby data (because you don’t change the game data). To make sure the game data is up to date, you can either get the data, wait a bit, then update the data, or just wait then get the data.
Again though, this is just something I’m thinking might work. I was actually wondering why games like BedWars by Easy.gg have such long loading times (this game uses sub places for games). It takes BedWars about 5-10 seconds to fetch their data, which is pretty much just stats and xp (for reference, it normally takes under a second to get data).
A similar idea that might work, you could have a primary key with all of you data on it, the in game save to a secondary key that saves changes. For example, your primary key might have 10 wins on it, then in game the player gets 1 win. When the player finishes, the 1 win is saved to the secondary key, which stores the changes that should be made to the data. When the player then joins the lobby again:
The primary key is fetched.
The secondary key is fetched:
If there is data on the secondary key, it’s added to the primary key and the secondary key is erased
If there isn’t data on the secondary key, the lobby tries to fetch it 1-2 more times after 4-10 second delays, and if it ever gets it the data is added and the key is erased.