You should use return
before both calls to DataStore:SetAsync(Player)
. Can you reply with your updated code and a screenshot of the error?
The warning message is “argument 2 missing or nil” and I just tried out @Wigglyaa’s method but it still only prints 1 retry.
Players.PlayerRemoving:Connect(function(Player)
local SaveData = {
Time = Player.leaderstats.Time.Value,
RobuxDon = Player.leaderstats.RobuxDon.Value
}
local retries = 0
repeat
local success, errormessage = pcall(function()
return DataStore:SetAsync(Player)
end)
if not success then
retries += 1
warn(retries)
task.wait(retries)
end
until success or retries >= 5
--I would also add:
if retries == 5 then
warn(Player.Name, "data not saved")
--additional handling/warning etc
end
end)
The thing is though I don’t want it to work, because I want to test the retry system. my data saving system already works i’m just testing my retry system.
And the problem with my retry system is that it only retries once instead of 5 times if I make the delay longer. If I make the task.wait one second it will only retry once for some reason.
Maybe it’s due to the fact the games shutting down?
I thought it could be that actually so how long do I have until the game shuts down? And is there a way to fix this then? To give it a longer delay and let it retry fully?
The problem is that the game closes after the player leaves. Your code should work. However, you should use something like this solution below with BindToClose
to keep the server from shutting down. The official documentation has a code sample for saving player data before shutting down.
connecting to a bindtoclose i assume but im not sure.
ahhh I guess my assumption was right?
I was given advice not to do that though a while ago because they said if your saving system works a bind to close might cause more incovenience or something.
yeah, you are really our forgotten past aren’t you. you brought back the bind to close method which was something from the past.
this might help
Why does he use ipairs though to loop through the players in the bindtoclose method?
If you are testing in studio it doesn’t actually wait til all threads have finished (or 30 seconds) as it assumes you might want to get on with something else!
Add a bind to close with a task.wait(20) and it should let the thread complete.
because the player’s removing function stops working as the game shutdown
I thought it might be because ipairs doesn’t continue to loop through when it finds a nil value possibly preventing error?
Also how does the player removing function not working link to using ipairs?
I was told by the same guy in a different topic not to use bindtoclose
So should I get rid of the retry system on the player removing event and move it into the gamebindtoclose?
Also what do you mean by the task.wait(20)? Can you give some code examples please?
Bind to close and player removing run at different times.
Anytime a player leaves the game you would probably want to save their data, and would likely have time to retry multiple times.
However if the server closes for another reason, you’ll probably want to try and save everyone’s data then as well! Only issue is the players might not be ‘removed’ triggering the player removing event.
Tldr, save and retry for both player.removing and bindtoclose
I assume the OP of the that just did it out of preference and since it’s a normal array used it instead
Okay, but does taht mean that I can’t make the delay longer on the player removing event because it won’t retry all the times?