Hi, today DataStore:SetAsync() randomly stopped working. It doesn’t produce an error, it doesn’t do anything really. Here is my script.
game.Players.PlayerRemoving:Once(function(player)
local sucess, errormsg = pcall(function()
print(tonumber(player.leaderstats.Tuba.Value))
checkpointstore:SetAsync(player.UserId,tonumber(player.leaderstats.Tuba.Value))
end)
if sucess then
print("Sucessfully saved "..player.Name.."'s Data")
else
warn(errormsg)
end
end)
For some context (if needed) the number it prints is 5 but when I rejoin the game it has the previous number aka 4
I don’t think it’s SetAsync() itself, but what I think it could possibly be is this line here
tonumber(player.leaderstats.Tuba.Value)
You’re using a tonumber, which is not really necessary. What you could do is make sure that the leaderstats are loaded first. Basically just if not leaderstats then return end
Then make sure that you have the value locally. Tuba = (Wherever this goes. Leaderstats most likely)
Same thing, I was using :Connect() before but switched to :Once() to see if it was the problem. Removed tonumber and changed :Once() to :Connect(), didn’t fix.
This worked. I still don’t know what the issue was.
game:BindToClose(function()
local sucess, errormsg = pcall(function()
checkpointstore:SetAsync(plr.UserId,plr.leaderstats.Tuba.Value)
end)
if sucess then
print("Sucessfully saved "..plr.Name.."'s Data")
else
warn(errormsg)
end
end)
--ServerScript in ServerScriptService
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local checkpointstore = DataStoreService:GetDataStore("Checkpoints")
local function save(player)
checkpointstore:UpdateAsync(player.UserId,function()
return player.leaderstats.Tuba.Value
end)
end
Players.PlayerRemoving:Connect(save)
game:BindToClose(function()
for _,player in Players:GetPlayers() do
save(player)
end
task.wait(2)
end)
Sorry was still putting it together.. Why waste it.
the server was closed, deleted from existence, before it could save any data. basically, when a server is 1 player when said 1 player leaves the server gets separation anxiety and dies, before the data can save