Datastore2, :Set() when player is leaving

i have a couple of folders with content that i want to save.
i tryed

players.PlayerRemoving:Connect(function(player)
local PetStore = DataStore2("Pets", player)
...
...
...
PetStore:Set({["PetData"] = PetData, ["PlayerData"] = PlayerData})
end)

and it is not saving

i checked the order in wich dataastore works.
it does run the set command before the save.

however the data is not saved

tryed the BeforeSave(modifier: (dataValue: any) => any).
same issue.

both test are in game (not in studio)

if i test it in studio… it somewhow does works

It might be because DataStore2 does not by default save data in studio. To make it save in studio you will need to create a BoolValue in server storage called SaveInStudio and set it to true in the property’s.

Are PetData & PlayerData Instances or tables? You can’t save Instances in Datastores, which is obvious to why.

1 Like

Datastore2 does not work as setting it when you leave as from how im aware, it does nothing. for datastore2 you set it whenever something changes mid-session as that is one of the benefits of it since it will auto save whenever a player is leaving, you also need a boolValue with the name of “SaveInStudio” to well, save in the studio

if you read the post. at the bottem it states that it doesn`t save in game, in studio it works fine

i turn the 2 folders in a table with the info i need

i have the bool value , and in studio it works

in game it first save the data to datastore… then sets the data in datastore2

and i dont know how to reverse that

ok , so i have found a solution, but it is a bad one.
datastore uses player.ancestortchanged to start the saving proces.
i put a wait directly after that

it is a sin. but it works

Any updates on this? I am experiencing the same issue and would prefer a less ‘hacky’ solution.

1 Like