so people on my group wall keep complaining about data loss, i have no idea why since i have never lost data, maybe its my script?
giving data + auto save script
local dsm = ds:GetDataStore("Main")
game.Players.PlayerAdded:Connect(function(plr)
local z = 0
local char = plr.Character or plr.CharacterAdded:Wait()
local newf = Instance.new("Folder", plr)
newf.Name = "data"
local newv = Instance.new("StringValue",newf)
newv.Name = "Character"
newv.Value = "None"
local newp = Instance.new("NumberValue", newf)
newp.Name = "Points"
char:FindFirstChild("Humanoid").Died:Connect(function()
print("yes")
plr.data.Character.Value = "None"
end)
local news = Instance.new("NumberValue", plr)
news.Name = "Stamina"
news.Value = 3
local rn = Instance.new("BoolValue", char)
rn.Name = "Running"
local sc = Instance.new("BoolValue", char)
sc.Name = "screen"
task.spawn(function()
pcall(function()
repeat
task.wait(0.5)
local running = plr.Character:FindFirstChild("Running")
local scren = plr.Character:FindFirstChild("screen")
if running.Value == false and scren.Value == false then
if news.Value ~= 3 then
news.Value += 0.5
end
end
until z == 2525
end)
end)
local newls = Instance.new("Folder", plr)
newls.Name = "leaderstats"
local newc = Instance.new("NumberValue", newls)
newc.Name = "Coins"
local newcf = Instance.new("Folder", newf)
newcf.Name = "Characters"
local tsmowned = Instance.new("BoolValue", newcf)
tsmowned.Name = "TSM"
local smowned = Instance.new("BoolValue", newcf)
smowned.Name = "SM"
local lcowned = Instance.new("BoolValue", newcf)
lcowned.Name = "LCM"
local donated = Instance.new("NumberValue", plr)
donated.Name = "Donated"
local tcowned = Instance.new("BoolValue", newcf)
tcowned.Name = "TCM"
local tvowned = Instance.new("BoolValue", newcf)
tvowned.Name = "TV"
local scmowned = Instance.new("BoolValue", newcf)
scmowned.Name = "SCM"
local ttvowned = Instance.new("BoolValue", newcf)
ttvowned.Name = "TTV"
local ttvcowned = Instance.new("BoolValue", newcf)
ttvcowned.Name = "TTVC"
local utsmowned = Instance.new("BoolValue", newcf)
utsmowned.Name = "UTSM"
local ncmmowned = Instance.new("BoolValue", newcf)
ncmmowned.Name = "NCM"
local utcmowned = Instance.new("BoolValue", newcf)
utcmowned.Name = "UTCM"
local nv = Instance.new("BoolValue", plr)
nv.Name = "Loaded"
nv.Value = false
local dse = ds:GetDataStore("Main")
local ledata
local succes, errored = pcall(function()
ledata = dse:GetAsync(plr.UserId)
end)
if succes then
pcall(function()
newp.Value = ledata[1]
tsmowned.Value = ledata[2]
smowned.Value = ledata[3]
lcowned.Value = ledata[4]
donated.Value = ledata[5]
tcowned.Value = ledata[6]
tvowned.Value = ledata[7]
scmowned.Value = ledata[8]
ttvowned.Value = ledata[9]
ttvcowned.Value = ledata[10]
utsmowned.Value = ledata[11]
ncmmowned.Value = ledata[12]
utcmowned.Value = ledata[13]
end)
nv.Value = true
end
if errored then
local try1
local succes, errored = pcall(function()
try1 = dse:GetAsync(plr.UserId)
end)
if succes then
newp.Value = try1[1]
tsmowned.Value = try1[2]
smowned.Value = try1[3]
lcowned.Value = try1[4]
donated.Value = try1[5]
tcowned.Value = try1[6]
tvowned.Value = try1[7]
scmowned.Value = try1[8]
ttvowned.Value = try1[9]
ttvcowned.Value = try1[10]
utsmowned.Value = try1[11]
ncmmowned.Value = try1[12]
end
if errored then
plr:Kick()
end
end
while wait(60) 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,
plr.data.Characters.UTCM.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)
player removing and bindtoclose handler script:
pcall(function()
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,
plr.data.Characters.UTCM.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
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
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("good")
end
end
end
end
end)
end)
game:BindToClose(function()
pcall(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,
v.data.Characters.UTCM.Value
}
if v.Loaded == true then
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
end)
end)