So I made a datastore saving script and put both BindToClose and PlayerRemoving (It’s a singleplayer game but there could be multiplayer as well - in other places). It all works fine and saves but I got a warning about too many requests (in this case, 2 at the same time), so I added a variable that should change in the BindToClose function so the PlayerRemoving won’t run. The problem is sometimes it runs anyway, so hence the warning. All I want to know is if the warning is a major problem and if there is any way I can fix it. I saw some people try to kick the players with BindToClose or just put a wait in there and let the PlayerRemoving function run, but that’s probably not the solution here. I also didn’t add autosaving since the values rarely change and it would be useless. Thanks.
We need to see some code, otherwise we cannot help you.
Well as I said, the saving works just fine I’m not looking for fixing my code. All I need is the best way to not overload with these two functions, since I saw a lot of people with a lot of other solutions that sometimes didn’t work.
I dont think it will be a major issue. Two requests were sent at the same time, and only one the first one that started will run. You can check for the opposite too, if you want (if playerremoving, change variable so bindtoclose doesnt run), which will complete what you meant to do. I think adding periodic saves or a save button, along with a save warning might also be good. I am not sure how frequent this would happen, but a server will wait a limited time for your bindtoclose function to end, so in cases the save function fails or take too long to finish, the data wouldnt be saved. This might be a reason for you to not even use playerremoving, but only bindtoclose. If playerremove fires first, bindtoclose might end before you expected, and the game will shutdown before saving.
In the end, I decided to leave it like I initially made it because I also tested with a local server and 2 players and it worked just fine. I didn’t change the variable in the PlayerRemoving because that could risk only one player to have its data saved. Thanks anyway.
Oh, I didnt see that you mentioned it could be multiplayer too.