I have created a datastore that is supposed to save. It saves a table into the datastore, but the moment I add another value to the datastore, the whole thing does not even save once. I have already tried modifying both values of the datastore before leaving the game and it did not save at all.
By the way, the datastore saves in normal gameplay, but not in play test, and it works whenever I use the server testing thing. How do I make it possible to save in play test with two values?
Here is my code. Please help, I do not understand why it is not saving.
game.Players.PlayerRemoving:Connect(function(plr) modded_data = game.DataStoreService:GetDataStore("ModdedData") local random_values = plr.Folder local stuff = {} -- do the serialization :) for i,v in pairs(random_values:GetChildren()) do stuff[v.Name] = v.Value end print(stuff) local success, err = pcall(function() modded_data:SetAsync(plr.UserId, stuff) end) if success then print('The player data of the user '..plr.Name..' has been saved successfully.') elseif err then print(err) end end)
I have resolved the problem and found out that I just need to use the BindToClose function in order to stop the server from shutting down while saving data.
It may have a time limit of 30 seconds, but I feel that is enough.
Here try this, It saves at all times
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(plr) wait() local plrkey = "id_"..plr.UserId local save1 = plr.leaderstats.Stage -- Change this to your leaderstat name local save2 = plr.leaderstats.Coins -- If you only have one leaderstat then remove this local GetSaved = ds:GetAsync(plrkey) if GetSaved then save1.Value = GetSaved[1] save2.Value = GetSaved[2] else local NumberForSaving = {save1.Value, save2.Value} ds:GetAsync(plrkey, NumberForSaving) end end) game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Stage.Value, plr.leaderstats.Coins.Value}) end)