**local ds = game:GetService(“DataStoreService”)
local dsm = ds:GetDataStore(“Main”)
task.spawn(function()
game.Players.PlayerAdded:Connect(function(plr)
local nv = Instance.new(“BoolValue”, plr)
nv.Name = “Loaded”
nv.Value = false
task.spawn(function()
task.wait(5)
nv.Value = true
end)
task.wait(5)
repeat
wait()
until plr.CharacterAppearanceLoaded
local dse = ds:GetDataStore(“Main”)
local gd = dse:GetAsync(plr.UserId)
if gd then
pcall(function()
plr.data.Points.Value = gd[1]
plr.data.Characters.TSM.Value = gd[2]
plr.data.Characters.SM.Value = gd[3]
plr.data.Characters.LCM.Value = gd[4]
plr.Donated.Value = gd[5]
plr.data.Characters.TCM.Value = gd[6]
plr.data.Characters.TV.Value = gd[7]
plr.data.Characters.SCM.Value = gd[8]
plr.data.Characters.TTV.Value = gd[9]
plr.data.Characters.TTVC.Value = gd[10]
plr.data.Characters.UTSM.Value = gd[11]
plr.data.Characters.NCM.Value = gd[12]
end)
end
task.spawn(function()
while wait(120) do
local stufftosave = {
plr.data.Points.Value,
plr.data.Characters.TSM.Value,
plr.data.Characters.SM.Value,
plr.data.Characters.LCM.Value,
plr.Donated.Value,
plr.data.Characters.TCM.Value,
plr.data.Characters.TV.Value,
plr.data.Characters.SCM.Value,
plr.data.Characters.TTV.Value,
plr.data.Characters.TTVC.Value,
plr.data.Characters.UTSM.Value,
plr.data.Characters.NCM.Value
}
if plr.Loaded.Value == true then
local succes, erromsg = pcall(function()
local dse = ds:GetDataStore("Main")
dse:UpdateAsync(plr.UserId, function(oldvalue)
if stufftosave ~= oldvalue then
return stufftosave
end
end)
end)
if succes then
print("saved")
else
warn(erromsg)
end
end
end
end)
end)
end)
task.spawn(function()
game.Players.PlayerRemoving:Connect(function(plr)
local stufftosave = {
plr.data.Points.Value,
plr.data.Characters.TSM.Value,
plr.data.Characters.SM.Value,
plr.data.Characters.LCM.Value,
plr.Donated.Value,
plr.data.Characters.TCM.Value,
plr.data.Characters.TV.Value,
plr.data.Characters.SCM.Value,
plr.data.Characters.TTV.Value,
plr.data.Characters.TTVC.Value,
plr.data.Characters.UTSM.Value,
plr.data.Characters.NCM.Value
}
if plr.Loaded.Value == true then
local succes, erromsg = pcall(function()
local dse = ds:GetDataStore("Main")
dse:UpdateAsync(plr.UserId, function(oldvalue)
if stufftosave ~= oldvalue then
return stufftosave
end
end)
end)
if succes then
print("saved")
else
warn(erromsg)
end
end
end)
end)
game:BindToClose(function()
for i,v in game.Players:GetChildren() do
local stufftosave = {
v.data.Points.Value,
v.data.Characters.TSM.Value,
v.data.Characters.SM.Value,
v.data.Characters.LCM.Value,
v.Donated.Value,
v.data.Characters.TCM.Value,
v.data.Characters.TV.Value,
v.data.Characters.SCM.Value,
v.data.Characters.TTV.Value,
v.data.Characters.TTVC.Value,
v.data.Characters.UTSM.Value,
v.data.Characters.NCM.Value
}
local succes, erromsg = pcall(function()
local dse = ds:GetDataStore("Main")
dse:UpdateAsync(v.UserId, function(oldvalue)
if stufftosave ~= oldvalue then
return stufftosave
end
end)
end)
if succes then
print("saved")
else
warn(erromsg)
end
end
end)
**
help with data loss my code is the above and it happens often as i gotta keep restoring data