Hello, I save data when the player joins and leaves using game:GetService(“DataStoreService”). I’m just asking, what is a reliable way to save a table full of a players plot data? for example, How do I save 100 different parts in a single table when the last player leaves without data loss?
I’m thinking maybe I have a table being editted in a script so that when they leave the game it doesnt have to loop through their data, it just already has it. I could also make all of its properties into one string. For example
Local PartTypes = {
[1] = "Part"
}
Local PlayerData = {
[
1 -- part type
5 -- position
3 -- color3
3
3
]
}
where the first number represents the part type, the second represents the position, and the 3rd represents the color3. do you think this method is a good idea?
You can store a lot of info without Experiencing Data loss, You would need to Store there names, or a part of there Data, You have 4MB of data you can save per key
When a player is leaving the game, the server can get closed before the script fully saves everything (at least from my experience.) I had like 15 different attributes and when they left the game I would loop through a table with the attribute names then when I finished looping I would save the data but it would sometimes lose their data.
I’m asking is doing
local data = {
[“Plot”] = {
15333, “etc”
}
}
game:GetService("DataStoreService"):GetDataStore("Data"):SetAsync(plr.UserId, data)
better than doing
local data = {}
for i,v in pairs(workspace.plot:GetChildren()) do
table.insert(data, {
["Type"] = part.ClassName,
["Pos"] = part.Position,
["Color"] = part.Color3
}
end
game:GetService("DataStoreService"):GetDataStore("Data"):SetAsync(plr.UserId, data)
That’s why you have a Singular Table Handling the Data, You would Apply the Data to the Attributes, and when there is a change, use GetAttributeChangedSignal and Set the Attributes Value to the Key Assigned on the Table, Then when the Player Leaves, you would only save one item (technically), that’s usually how I do DataStores and that usually helps with Preventing Data Loss.
And The Server Closes if All Players leave, or All Players are kicked, it can also happen on a forced shutdown, which is why people recommend setting up a BindToClose function in case of that
The Second Option is better, You would be more Organized with your Data rather than having random numbers in a key
wouldnt the second option cause data lossd? also I would decipher the “Random numbers” into actual meaning. As said before, The first “Random Number” is the part type, the second is the position, and the 3rd is the color3.
it would also let me players build more things since each part takes up less space to save
That’s not how Data Loss works, Data Loss happens when DataStore’s fail to Load or Fail to Save, Your Data should be fine depending on how you handle it, Data Loss can be prevented (Or at least less common)
Not exactly, Studio automatically creates a Key for the Table’s Values, You may think it would be:
{"Pos", "Num", "Color"}
But its Actually:
[1] = "Pos"
[2] = "Color"
[3] = "Num" -- The Order of your Values can be changed as well
[1], [2], and [3] are keys automatically given to the Values.
You could, but that would just be tedious to split up. (assuming you have 3 Values within a key that would just be compacting the Table),
either way, you are unlikely to reach a limit as DataStore’s can hold up to 4MB which is roughly 4 million characters, and 1 Character is 1 byte (0.000001 of a MB), So you wouldn’t really need to do it as you are unlikely to reach any limit, it doesn’t make it more likely you will experience Data Loss.
I still Recommend the Second Option because of that.
(Kind of Off Topic):
Its Just Data Loss, which can be prevented. DataStores can fail, Its just a normal occurrence, it can happen anywhere, People found ways to prevent it almost completely however