So in my game I have a combat logging system, if on player removing you have a combat tag it will adjust ur data to punish u for combat logging. However BindToClose fires AFTER player removing events so how could I check if the game is shutting down during the player removing event?
Would it be a good idea to do something like task.wait(1) before checking for a combat log? Or could it be inconsistent.
Instead of checking if the game is shutting down, why not check to see how many players are left in the game during PlayerRemoving? If the player is the only one left in the entire server and coincidentally leaves while having combat log, do not inflict any punishments.
Ah, I was under the impression that the combat log system strictly applies to a PvP environment.
What I gather from this, you are attempting to check if a server has crashed/shutdown which explains why a server would close with more than 1 player. In this case, there is no other way besides :BindToClose() to check for this.
Why not add the combat logging on the PlayerRemoving event? You can always insert a folder inside of ServerStorage keeping track of all combat tags. When the player leaves, you can punish the player by adjusting their Data using DataStoreService.
So why would you need to check if it is shut down? I am just asking because maybe the solution to the problem can be found without checking for a shutdown because I think it isn’t possible to check if Roblox has shut down. Maybe by checking memory usage.
I did something similar before, instead of setting the data on player removing I set a boolean and when they rejoined I would punish them with adjusting their data. However I can no longer do it on rejoin as now my game forces you to drop your loot when you combat log.
Maybe something to do with memory or something would be the right solution.
My worse case solution is having a custom command in-game to shutdown all servers with message service. But if a server crashes people will get combat logged which can very well happen so I do want to fix this problem.
Ok so I found a potential solution but one issue remains.
~ Save what the players data was before combat logging as a variable, then adjust the data to punish them
~ setup event so that on shutdown we set the data back to the saved variable.
~ Disconnect that shutdown event after 30 seconds (since shutdowns run functions for a maximum of 30 seconds before force shutting down)
Now the issue with this solution is that what if they simply combat log before a shutdown or crash occurs? You may be thinking “Well so what” but the issue is this could leave a dupe in my game since u drop loot on death. Someone could open the loot bag and take out items before a shutdown if u actually combat logged before a shutdown occurred.
I added a property to the loot bags called “BeenOpened” so I can check if their loot bag has been opened. If they combat log and their loot bag hasn’t been opened during a shutdown then I reset the data. Realistically if u clog during a real shutdown nobody would be able to open ur loot bag so this cant create any issues. Only thing someone can do is potentially combat log 30 seconds before a shutdown but combat tags last 60 seconds anyways so the shutdown probably would’ve clog checked them anyways.