Hello!
I’ve run into another issue, when I am doing :SetAsync(), it seems not to work.
function saveData(player)
local key = 'PLAYERDATA_'..player.UserId
local playerFolder = player:FindFirstChild('PlayerData')
function convertInstanceToData(currentFolder)
local returnedData = {}
for i,v in pairs(currentFolder:GetChildren()) do
if v:IsA('Folder') then
returnedData[v.Name] = convertInstanceToData(v)
else
returnedData[v.Name] = v.Value
end
end
return returnedData
end
local constructedTable = convertInstanceToData(playerFolder)
print(constructedTable)
local successful, errorMessage = pcall(function()
dataStore:SetAsync(key, constructedTable)
end)
print(tostring(errorMessage))
end
players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, player in pairs(players:GetPlayers()) do
coroutine.wrap(saveData)(player)
end
end)
Outputs:
{
["Coins"] = "0",
["Completed Obbies"] = "0",
["Inventory"] = ▼ {
["Accessories"] = {},
["Gear"] = {},
["Packages"] = {}
},
["Wins"] = "0"
}
which is what I expect. However, when I rejoin and print the data, it’s always nil.
players.PlayerAdded:Connect(function(player)
local key = 'PLAYERDATA_'..player.UserId
local data
local successful, errorMessage = pcall(function()
data = dataStore:GetAsync(key)
end)
print(data) -- nil
if successful then
if not data then
data = defaultData
end
verifyData(data, player)
else
print(tostring(errorMessage))
end
end)
Edit: Tested in an actual game and it works, but :SetAsync(), I just can’t get it to work in studio.