All of a sudden today my datastore started to break, I’ve only added two new folders that should get saved along with the data in them and I’ve not modified my datastore before doing so because it would be automatically handled.
I’ve narrowed it down to being a :GetAsync() issue because “Passed Locals” never gets printed, however the pcall prints no errors and I have no clue why.
The way the datastore works is that it saves the names of the attributes / basevalues’ parents, their names and their attributes / values and once the player joins folders get created by a different script and the saved instances get created and parented to the existing paths.
This is not a replication issues as far as I’ve tested it, I’ve also tried wiping my data and getting a new set of data incase anything got corrupted and it still won’t work.
This is the new code I’ve had to write, and it only works about 20% of the time.
local dss = game:GetService("DataStoreService")
local store = dss:GetDataStore("GeneralSavedData")
local coordinatedata = dss:GetDataStore("CoordinateData")
local blacklist = {
["Studs"] = true,
}
local function save(plr)
print("Started Saving")
local data = {}
local saved = {}
local savedinstances = {}
local success, err = pcall(function()
saved = store:GetAsync(tostring(plr.UserId)) or {}
end)
if not success then
warn("GetAsync failed for", plr.Name, err)
saved = {}
end
print("Passed locals")
for _, v in pairs(saved) do
local name, _, _, parentname = unpack(v)
savedinstances[name] = parentname
end
local function processDescendants(parent)
print("Processing "..parent.Name)
for _, v in pairs(parent:GetDescendants()) do
if not blacklist[v.Name] then
print("Saving "..v.Name)
if v:IsA("ValueBase") then
data[#data + 1] = {v.Name, v.Value, nil, v.Parent.Name}
elseif v:IsA("Configuration") then
for att, val in pairs(v:GetAttributes()) do
local t = typeof(val)
if t == "number" or t == "string" or t == "boolean" then
data[#data + 1] = {v.Name, val, att, v.Parent.Name}
end
end
data[#data + 1] = {v.Name, nil, nil, v.Parent.Name}
end
end
end
end
processDescendants(plr.leaderstats)
processDescendants(plr.PlayerData)
local success2, err2 = pcall(function()
print("Set Async")
store:SetAsync(tostring(plr.UserId), data)
end)
if success2 then
print("General data saved successfully for player " .. plr.Name)
else
warn("Failed to save general data for player " .. plr.Name .. ": " .. tostring(err2))
end
end
local function load(plr)
local data = store:GetAsync(tostring(plr.UserId))
if not data then return end
local createdInstances = {}
for i = 1, #data do
local name, value, attribute, parentname = unpack(data[i])
local parent
if parentname == "leaderstats" then
parent = plr.leaderstats
else
parent = plr.PlayerData:FindFirstChild(parentname, true)
end
if not parent then
warn("Parent instance not found: " .. tostring(parentname))
continue
end
local instKey = parent:GetFullName() .. "." .. name
local inst = parent:FindFirstChild(name, true)
if not inst then
if attribute then
inst = Instance.new("Configuration")
elseif typeof(value) == "boolean" then
inst = Instance.new("BoolValue")
elseif typeof(value) == "number" then
inst = Instance.new("NumberValue")
elseif typeof(value) == "string" then
inst = Instance.new("StringValue")
else
inst = Instance.new("Configuration")
end
inst.Name = name
inst.Parent = parent
end
if attribute and inst then
inst:SetAttribute(attribute, value)
elseif inst and inst:IsA("ValueBase") and value ~= nil then
inst.Value = value
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
task.wait(0.25)
load(plr)
end)
game.Players.PlayerRemoving:Connect(function(plr)
save(plr)
if workspace.temp.Checkpoints:FindFirstChild(plr.Name.."'s Checkpoint") then
workspace.temp.Checkpoints:FindFirstChild(plr.Name.."'s Checkpoint"):Destroy()
end
end)
I’ve also reverted the datastore to it’s previous code and even removed the new folders that should’ve been saved yet the same issue still persists, with :GetAsync() still not printing any errors.
The original datastore code still works in the published version, not the studio one.
This is the previous (original) script:
local dss = game:GetService("DataStoreService")
local store = dss:GetDataStore("GeneralSavedData")
local coordinatedata = dss:GetDataStore("CoordinateData")
local blacklist = {
["Studs"] = true,
}
local function save(plr)
local data = {}
local saved = store:GetAsync(tostring(plr.UserId)) or {}
local savedinstances = {}
for _, v in pairs(saved) do
local name, _, _, parentname = unpack(v)
savedinstances[name] = parentname
end
local function processDescendants(parent)
for _, v in pairs(parent:GetDescendants()) do
if not blacklist[v.Name] then
if v:IsA("BoolValue") or v:IsA("StringValue") or v:IsA("NumberValue") then
data[#data + 1] = {v.Name, v.Value, nil, v.Parent.Name}
elseif v:IsA("Configuration") then
local attributes = v:GetAttributes()
if attributes then
for att, val in pairs(attributes) do
data[#data + 1] = {v.Name, val, att, v.Parent.Name}
end
end
data[#data + 1] = {v.Name, nil, nil, v.Parent.Name}
end
end
end
end
processDescendants(plr.leaderstats)
processDescendants(plr.PlayerData)
local success, err = pcall(function()
store:SetAsync(tostring(plr.UserId), data)
end)
if success then
print("General data saved successfully for player " .. plr.Name)
else
warn("Failed to save general data for player " .. plr.Name .. ": " .. tostring(err))
end
end
local function load(plr)
local data = store:GetAsync(tostring(plr.UserId))
if not data then return end
local createdInstances = {}
for i = 1, #data do
local name, value, attribute, parentname = unpack(data[i])
local parent
if parentname == "leaderstats" then
parent = plr.leaderstats
else
parent = plr.PlayerData:FindFirstChild(parentname, true)
end
if not parent then
warn("Parent instance not found: " .. tostring(parentname))
continue
end
local instKey = parent:GetFullName() .. "." .. name
local inst = parent:FindFirstChild(name, true)
if not inst then
if attribute then
inst = Instance.new("Configuration")
elseif typeof(value) == "boolean" then
inst = Instance.new("BoolValue")
elseif typeof(value) == "number" then
inst = Instance.new("NumberValue")
elseif typeof(value) == "string" then
inst = Instance.new("StringValue")
else
inst = Instance.new("Configuration")
end
inst.Name = name
inst.Parent = parent
end
if attribute and inst then
inst:SetAttribute(attribute, value)
elseif inst and inst:IsA("ValueBase") and value ~= nil then
inst.Value = value
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
task.wait(0.25)
load(plr)
end)
game.Players.PlayerRemoving:Connect(function(plr)
save(plr)
if workspace.temp.Checkpoints:FindFirstChild(plr.Name.."'s Checkpoint") then
workspace.temp.Checkpoints:FindFirstChild(plr.Name.."'s Checkpoint"):Destroy()
end
end)