Hey I’m trying to save the data stores once the player leaves, however it doesn’t work, it doesn’t even print anything.
Here’s the code:
game.Players.PlayerRemoving:Connect(function(plr)
local ID = plr.UserId
local PlayerStats = plr.PlayerStats
local PlayerProjects = plr.PlayerProjects
local ToSave = {}
for i, v in pairs(PlayerStats:GetChildren()) do
ToSave[v.Name] = v.Value
end
ToSave["Projects"] = {}
if #PlayerProjects:GetChildren() > 0 then
for _, p in pairs(PlayerProjects:GetChildren()) do
ToSave["Projects"][p.Name] = {}
for i, v in pairs(p:GetChildren()) do
if v.ClassName ~= "Folder" then
ToSave["Projects"][p.Name][v.Name] = v.Value
else
ToSave["Projects"][p.Name][v.Name] = {}
if #v:GetChildren() > 0 then
for index, feature in pairs(v:GetChildren()) do
ToSave["Projects"][p.Name][v.Name][feature.Name] = feature.Value
end
end
end
end
end
end
local success, err = pcall(function()
DSService:SetAsync(ID, ToSave)
end)
if success then
print("success")
else
warn(err)
end
end)
I read it a few hours ago (awesome tutorial by the way),
added this earlier just didn’t include in the post yet still doesn’t work:
game:BindToClose(function()
if game:GetService("RunService"):IsStudio() then return end
local Players = game:GetService("Players"):GetPlayers()
for _, plr in pairs(Players) do
local ID = plr.UserId
local PlayerStats = plr.PlayerStats
local PlayerProjects = plr.PlayerProjects
local ToSave = {}
for i, v in pairs(PlayerStats:GetChildren()) do
ToSave[v.Name] = v.Value
end
ToSave["Projects"] = {}
if #PlayerProjects:GetChildren() > 0 then
for _, p in pairs(PlayerProjects:GetChildren()) do
ToSave["Projects"][p.Name] = {}
for i, v in pairs(p:GetChildren()) do
if v.ClassName ~= "Folder" then
ToSave["Projects"][p.Name][v.Name] = v.Value
else
ToSave["Projects"][p.Name][v.Name] = {}
if #v:GetChildren() > 0 then
for index, feature in pairs(v:GetChildren()) do
ToSave["Projects"][p.Name][v.Name][feature.Name] = feature.Value
end
end
end
end
end
end
DSService:SetAsync(ID, ToSave)
end
end)