DataStore2 not to save on PlayerRemoving

I was reading into DataStore2 documentation and it said to NOT save data when player leaves, and I realised that’s exactly what I was doing, however it then goes onto say that it doesn’t matter (as well as not provide an example of what to actually do) So how can I fix my current code? I’ve never had data store problems with it, but I don’t want any risks in the future

https://kampfkarren.github.io/Roblox/guide/gotchas/

local function PlayerRemoving(player)
	DataManager.Save(player)
end

-- DataManager
function DataManager.Save(player)
	if player:FindFirstChild('PlayerData') then
		PlotManager.Save(player)
		
	    local PlayerDataStore = DataStore2(DataName, player)
	    local PlayerDataTable = Converter.Convert(player.PlayerData)
	    PlayerDataStore:Set(PlayerDataTable)
	end

	PlotManager.Clear(player)
end

Datastore2 auto save players data when they leave so you don’t need to, just get their data when they join and maybe saving it when the value changed.

It doesn’t though. Just tried it, data does not auto save whatsoever

Did you test in studio? It doesn’t save in studio tho

Tried online as well. Still doesn’t save

Just found this

  • You need to set your data stores as they change , not on PlayerRemoving.

The normal way of doing data stores is to keep a cache somewhere of a player’s data (such as in a folder or using leaderstats), then saving when the player leaves. It is wrong, however, to use DataStore2 this way . DataStore2 is built to be used whenever your data actually changes. You shouldn’t invoke DataStore2 in PlayerRemoving at all . Don’t worry, :Set will never error or do API calls, it’s all cached. DataStore2 will save the player’s data before they leave.

So then what’s the point of :Set() if data automatically saves?

For you to manually save players data if you want, Datastore2 was built to be able to save players data before changing the actual Values so the function is just for that (?). Also it’s convinient if you are using it like normal datastore

I don’t know what you mean there.

All I want is data to be saved at the final state of the player (when the players leaves, whatever) and to not have to worry about it possibly not saving

no it is not supposed to be saved in that typical manner, but rather as you already quoted above, each time a value changes.

Problem I have with that is I have so many values that get changed/added/removed and these changes coming from a dozen or so different scripts that I can’t just have every single script look out for each individual value change

use a module then , keep some function to save data in a module and require and save it through that for every player to prevent extra code

Read this thread
https://devforum.roblox.com/t/is-this-an-appropriate-way-to-save-datastore2/537805

Can see that I have data stored in a bunch of different folders and what not. It’s not a matter of just ‘changing a value’ I’m adding, removing values, adding removing folders, and much more.

I’m just gonna roll with what I got. Not getting anywhere, code currently works. If data gets lost then it’s more than likely Roblox’s problem (even tho DataStore2 is supposedly famed for data never being lost :man_shrugging:)

PlayerDataStore.OnUpdate:Connect(function()
PlayerDataStore:Save()
end)

hey bro! how u doing with this? I’m the programmer of coins hero simulator (5k players in the best moment) and I’ve been experiencing data loss by so many players. Im not exagering if im saying i’ve read all the posts, topics and forums of datastore2 and they “”“”“”“”“data loss prevention”“”“”“”“”" and I don’t know what else to do. Supposedly doesnt matter if you leave the game, you get kicked for some reason, server restarts or get disconnected by internet issues. But not, many players at day says that they played like 6hs, get disconnected by lag or something and when they joined back the lost that played time, not getting reseted but the loose all that player hours. I’ve improved this issue a little bit because in former versions of the game i’ve been oversaturating ds2 by saving every coin you get (in the game you get a lot of different coins in seconds) i’ve fixed it by not using datastore2 in that case and just save like every 5 seconds your coins by a :Set()
Could we talk? we can discuss ideas and maybe we will solve it because of course… none of the creators of datastore2 answered me and everybody in my posts they say “ds2 is already handling dataloss and blablabla”
Have a nice day :slight_smile:

I gave up on DataStore2. Seemed like it didn’t work as they claimed it did. My own data store structure worked better + had features which DataStore2 lacked. Data loss is on Roblox for not handling DataStores correctly, and blame shouldn’t be put on the developer if they are doing data stores correctly.

could you helpme with your system? i can pay, im super exhausted and frustrated dealing with datastore2

1 Like

Sent a DM, check message :+1: can discuss there