so datastore2 says that you shouldnt save on PlayerRemoving.
it says that you are supposed to save when a value changes. but what if i have a big table with a lot of info? how am i supposed to do it since tables dont have a changed property? should i do a while loop, or save on ChildAdded() to the model where the table takes info from?
What i did, was make a command like “/save” that would save there progress in the game (also when they die), and its there fualt if they dont save when leave.
Also, with tables you could do this
local DS = game:GetService("DataStoreService"):GetDataStore("Data")
local table = {}
game.Players.PlayerAdded:Connect(function(player)
table = game:GetService("HttpService"):JSONDecode(DS:GetAsync("A-DataStore")) --setting the table
DS:SetAsync("A-DataStore",game:GetService("HttpService"):JSONEncode(table)) --saving
end)
i have decided to save data every 6 seconds. if my method wont work fine then ill maybe try yours
I think that is fine, just not too mutch because it might overwhelm the system. (i have gotten errors because im saving data too mutch)
Just wondering, what is your code and what are you saving?
all items player has placed down on their base, all items in the inventory and the inventory bar. its a complicated process because there is custom item system
So, are you saving a table or just alot of things with “-[name of thing]” after the name of the player
im saving a lot of tables. one table for each item, they look something like this
itemtable = {}
itemtable.Category = category
itemtable.ItemName = itemname
itemtable.ToSave = {this table contains info like amount, owner etc.}
itemtable.HasFolder = false (or true, this determines if the item has a folder, for example a chest has a folder where all of its items are stored)
itemtable.FolderItems = {contains tables like this one, which are the items from the folder}
If you would like to, you can put table inside of tables, it would help with the saving, so you could save one thing, and load one thing.
thats what my script is doing.
Just save whenever the value changes as the wiki says, providing that it’s not anything crazy like player position.
i have added saving every 6 seconds, no errors so far
i said that im saving tables which dont have the changed property