Hello,
This is the same situation as my previous topic, but now a slightly different problem; dictionaries that I’ve made to save when the player leaves are nil when the player loads in. Do number arrays and dictionaries in the same datastore cause issues?
I didn’t think that the old number arrays had much of an impact so I didn’t include them last time, but now I will (It was a big mistake on my part for not including them).
local plrKey = "stat_"..p.UserId
local GetSaved
local function GetData()
local sucess, err = pcall(function()
GetSaved = DS:GetAsync(plrKey)
end)
if GetSaved then
p.Class.Value = GetSaved[1]
pts.Value = GetSaved[2]
local num = 2
for i, v in pairs (p.ClassStats:GetChildren()) do
for i, e in pairs(v:GetChildren()) do
if e.Name ~= "TickTime" then
local t = {}
t = GetSaved[v.Name] or {}
if GetSaved[v.Name] ~= nil then
e.Value = GetSaved[v.Name][e.Name]
else
GetSaved[v.Name] = {}
end
print(t, GetSaved[v.Name])
end
end
end
for i, v in pairs (p.leaderstats:GetChildren()) do
if v.Name ~= "Points" then
num = num + 1
v.Value = GetSaved[num]
end
end
num = num + 1
local L = Instance.new("BoolValue")
L.Name = "loaded"
L.Parent = p
warn("Data Loaded")
end
end
GetData()
wait(1)
if GetSaved == nil then
GetData()
warn("Data Load failed, retrying")
wait(1)
if GetSaved == nil then
warn("Data Load failed, retrying")
GetData()
wait(1)
if GetSaved == nil then
warn("Data load failed")
local NumbersForSaving = {
p.Class.Value,
pts.Value,
}
for i, v in pairs (p.ClassStats:GetChildren()) do
for i, e in pairs(v:GetChildren()) do
if e.Name ~= "TickTime" then
NumbersForSaving[v.Name] = {}
NumbersForSaving[v.Name][e.Name] = e.Value
end
end
end
for i, v in pairs (p.leaderstats:GetChildren()) do
if v.Name ~= "Points" then
table.insert(NumbersForSaving, #NumbersForSaving + 1, v.Value)
end
end
local L = Instance.new("BoolValue")
L.Name = "loaded"
L.Parent = p
wait()
DS:GetAsync(plrKey, NumbersForSaving)
wait(1)
p:LoadCharacter()
end
end
end
game.Players.PlayerRemoving:Connect(function(p)
local Table = {
p.Class.Value,
p.leaderstats.Points.Value,
}
local f = p.ClassStats[p.Class.Value]
f["Time Played"].Value = f["Time Played"].Value + tick() - f.TickTime.Value
for i, v in pairs (p.ClassStats:GetChildren()) do
for i, e in pairs(v:GetChildren()) do
if e.Name ~= "TickTime" then
Table[v.Name] = {}
Table[v.Name][e.Name] = e.Value
end
end
end
for i, v in pairs (p.leaderstats:GetChildren()) do
if v.Name ~= "Points" then
table.insert(Table, #Table + 1, v.Value)
end
end
if p:FindFirstChild("loaded") then
local success, err = pcall(function()
DS:SetAsync("stat_"..p.UserId, Table)
end)
if success then
warn("Saved Data")
else
warn(err)
end
end
end)
