Hello everyone!
I am making a data saving system for my game, that works for getting the data but I have hit a wall when saving data.
This is the code I am using for saving the data:
Code
game.Players.PlayerRemoving:Connect(function(player)
local SavingPlayerData = {}
print("Player removing")
local key = "Player-"..player.UserId
local UnlocksFolder = player.UnlocksFolder:GetChildren()
for i, v in pairs(UnlocksFolder) do
savingPlayerData[v.Name] = v.Value
end
local EncodingDataString = HttpService:JSONEncode(SavingPlayerData)
print("About to save")
local success, err = pcall(function()
print("Saving")
DataStore:SetAsync(key, EncodingDataString)
print("Saved")
end)
print("After save")
if success then
print("Save Success")
else
print("Data not saved")
end
end)
As the player leaves the game, the code runs up until the part where it uses DataStore:SetAsync(key,EncodingDataString)
and prints all of the prints before. However, it refuses to pass this point. Nothing is printed after the SetAsync.
Is there anything that I’m doing wrong in this?
Thanks in advance