Datastore2 SaveAll() at playerRemoving?

Hi,

So im remaking my data (instead of saving data in different keys i want to save everything under 1 key) and i don’t know how could i save it because i have some number value datas, tables (quests etc.), booleans. I think i could save everything when i change it, but i can’t detect when table is changing (so i need to save it when i know that i added/removed something from there). I found a thing on API that should save everything at once but idk when should i use it. I thought i will use it at PlayerRemoving, but everyone says do not use DataStore2 at PlayerRemoving and now im confused. How will this thing behave with tables?

What do you guys recommend me to do?

1 Like

I’m not really good at working with datastores, but here’s a thread that might help, as well as some documentation from someone’s repo on GitHub. (Sorry I couldn’t help explain any of this to you, frankly, I’m not quite sure either.)

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

The gist of it seems to be that it’s presuming player data isn’t changing when PlayerRemoved is fired, so SaveAll does not need to be used because DataStore2 has already cached that before the player leaves. However, I’m also not super knowledgeable, so I’d probably listen more to the others in this thread rather than me.

That GitHub does seem to explain some of the basics of DataStore2 pretty well though.

1 Like

I think you should store all those things in one big table and save that table, it will reduce traffic and help stop some requests being dropped because you’re sending too many requests too fast

1 Like

That doesn’t that needs to be done I believe, DataStore2 automatically saves the data on game shutdown / player leave, and in events when your data changes too.

You can see this in the DataStore2, Documentation too:

DataStore2 is built to be used whenever your data actually changes. You shouldn’t invoke DataStore2 in PlayerRemoving at all .

2 Likes

so you mean something like this?
And save it into 1 key. But once again when should i save it? This is good because i should save only 1 time, but the point of DS2 is to save data when it changes, idk what should i do

local DATA = {
	Money = 0,
	GoodPlayer = true,
	Reputation = "sOmething",
	Quests = {
		Bla = 1,
		bla = 2,
	}
}
1 Like

So i can just :Set() my data when i change it and don’t do anything later?

Yeah exactly, everything else is done by the module itself.

I would also recommend you to use the Documentation of DataStore2, it has some basic usage examples:
https://kampfkarren.github.io/Roblox/guide/basic_usage/

2 Likes

Alright i will try this out later! I actually read it before but wasn’t trying to understand it (before i was doing :Set() at PlayerRemoving to save data)

Thanks everyone!

2 Likes