How To Overwrite Values In DataStore?

I’m no master at datastores, so my solution likely isn’t the best, but I would save the player’s data BEFORE even attempting to teleport the player (I’d cancel the PlayerRemoving save for them as well), that way the correct data is in place for Place2 to retrieve when the player arrives.

2 Likes

Could you elaborate why that could happen?
The game is saving on player leaving and saving on bind to close too, so usually place1 will save enough fast before joining place2 I guess

2 Likes

Oh, does task.wait(6) do the job? Cause I think it waits 6 seconds for the data to save before the place closes down. Also the issue is that the place 2 isn’t saving place 2 data, it’s loading place 1’s data instead.

Oh also I have the DataStore v3 plugin, so idk if that helps in anyway

2 Likes

Place2, indeed will load place1 data, and then save the place2 data

2 Likes

In order to do fix this, should I use the UpdateAsync instead of SetAsync?
Cause I still have no idea to fix it, unless I’m just being a bit slow right now

2 Likes

Nope, before changing that, you should be sure whats the real issue in here.
A first test I would try is saving on the datastore a timestamp and a keyword referencing each place1 and place2. So you can be sure what is exactly happening, which place saved the data you are seeing on screen

2 Likes

image
image

There are times when Place1 may be too slow to save the data or the player switches servers extremely fast, or both! Happened to me once when I server hopped too fast. Sigh, the world of race conditions is quite headache-inducing, isn’t it?

3 Likes

Sure, I trust you, and I know that many APIs of roblox usually fails, handling errors is extremely important.
Honestly I never experienced it that players arrive to a next place without the right data from previous place, on games with 35 players at the same time on the same server and lots of teleporting, but I handle datastores in different ways

2 Likes

So in place 2, it said the data has been saved, but also not? It said it doesn’t save when I call the players.PlayerRemoving function. But it saves when I call the save() function when the player joins.
image
The same thing happens for place 1 as well.

2 Likes

Thats probably because you have 2 functions to save the data. One when players leaves and one when server closes.

“The data Have Been SAVED WOO” Could came from game:BindToClose
And “Data didn’t save” came from players.PlayerRemoving

You cant save more than once the datastore of that player in less than 6 seconds.
So the first attemp did work and the second one didnt, you should print the err too

2 Likes

Smart idea, I went and printed it out. This is what printed out from the players.PlayerRemoving function.


Not sure where I’m using a string to concatenate with a boolean

2 Likes

The issue is this line:
print("This is data flashdrive witherws: "..game.ReplicatedStorage.PlayerData.GotFlashDrive.Value)

the GotFlashDrive is a boolean and you are trying to merge a text string with a true/false by using the dots …

Change it to this with a coma:
print("This is data flashdrive witherws:", game.ReplicatedStorage.PlayerData.GotFlashDrive.Value)

1 Like

Ah, oops. Thanks for catching that, I don’t really know what the format for printing values were lol.
And thank you for taking the time out of your day to help me

3 Likes