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)

1 comment
I did not need the answer... I just wanted to answer my own question, which all you need to do is use the BindToClose function which handles whenever you stop the server. Sorry for the downvote, but I already answered it, and I gave an explanation.