Hello guys, I am having a trouble saving data, here’s the code;
function module:SaveData()
if self.ToSave then
Datastore:UpdateAsync(self.Player.UserId, function(oldValue)
local previousData = oldValue or {DataId = 0}
if self.ToSave.DataId == previousData.DataId then
self.ToSave.DataId += 1
print('Success saving data :)')
print(self.ToSave)
return self.ToSave
else
return nil
end
end)
end
end
It prints success saving data and then it errors… when I print self.ToSave it outputs this;
Seems like the trouble is here;
function module:GetData()
local realTMP = require(script.template)
local suc,result = pcall(Datastore.GetAsync,Datastore,self.Player.UserId)
if (suc) then
if (result) then
for i,v in pairs(realTMP) do
if (result[i] == nil) then
result[i] = v
end
end
self.ToSave = result
return;
end
self.ToSave = realTMP.ToSave
end
end
Because self.ToSave = result Is not overriding self.ToSave it’s setting self.ToSave[“ToSave”] = result