I have a data save script, that fires whenever a player is removed and when the server shuts down
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, v in pairs(game.Players:GetPlayers()) do
saveData(v)
end
end)
The problem with this, is that when the last player in the server leave, both functions fire, and data will save twice. The problem with that is there will be this warning:
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1272029006-inventory
So how do I ensure the data is not saved twice? thanks a lot
If your reaching your limit I don’t think it is caused from that double saved, though you should fix that by checking how many players are there. But you should lower your requests, if you don’t really know how profile service deals with a lot of these issues!
I actually am having this same issue too, both of those functions tend to run when the game closes, so which one fires first? If we can figure that out, then maybe there’s a fix.
I’m not really sure how you could lower the request, unfortunately. I do recommend using ProfileService or Datastore2 since it I believe they make it really easy to save data and I haven’t run into any issues with the too many requests. The only thing I could think of is adding the unsaved data to a table and maybe trying to save it a couple of seconds later however not sure how this would work in a bind to close.
It creates a new thread, aka it won’t yield or wait for the next person to be done saving their data.
This can be helpful for stopping dataloss as it won’t take as long.
But how does it solve the double saving problem? you’re still having the 2 events (player removing and bind to close), and both should fire, but it doesn’t anymore.
in the guide you posted you had written the same thing
*I have no problem with data loss. I just don’t want the PlayerRemoving Event and BindToClose to fire together.