An issue I’m not sure how to solve is that since PlayerRemoving fires before BindToClose. If I’m saving the data in PlayerRemoving, I can’t set a condition for the saving process if the server is shutting down. For example when I shutdown I want to disable the combatlogging feature in the game. I could save again in the BindToClose, but saving it in both PlayerRemoving and BindToClose one after the other I’m afraid to run into overload and dataloss. How can I let the saving process withing PlayerRemoving know that the server is shutting down?
Change removing/leaving and shutdown/BindToClose to 1 function (if it isnt already)
Combat log or whatever should activate on leaves only set a value and detect shutdowns.
local ServerShuttingDown = false
local function saveData(player)
-- Saving stuff
if not ServerShuttingDown then
-- Server is NOT shutting down, add stuff here.
-- For server shutting down only do the opposite. (if ServerShuttingDown then)
end
end
game:BindToClose(function()
ServerShuttingDown = true
-- Change whats below with your BindToClose function ofc. But use the same function for saving data.
for _, v in pairs(game:GetService("Players") do
saveData(v)
end
end)
Hope this helped!
Note: You can also just make the PlayerRemoving function you have do the same
As in, add a variable for shutting down or not and update it with BindToClose, not sure if PlayerRemoving fires with this though
1 Like