Hello, i am working on a new datastore system and in a large server (300+ people) when Closing (Restarting for Update) this function does not fire and data of the player get lost.
This is actual the code wich i am using:
game:BindToClose(function()
for _, Player in ipairs(PlayerService:GetChildren()) do
if _G[Player.UserId] and _G[Player.UserId]["Stats"]["Saved"] == false and Player:FindFirstChild("PLAYER_STATS") and StudioMode == false then
local ArrayData = {
["Currency"] = {
["Cash"] = Player.PLAYER_STATS:GetAttribute("Money"),
["Diamonds"] = Player.PLAYER_STATS:GetAttribute("Diamond"),
},
["UserData"] = {
["PrisionTime"] = Player.PLAYER_STATS:GetAttribute("Prision_Time"),
["EXP"] = Player.PLAYER_STATS:GetAttribute("EXP"),
},
};
GAME_DB:UpdateAsync("User_" .. Player.UserId, function(OldData)
return ArrayData;
end)
_G[Player.UserId] = {};
end
end
end)
Before anyone says the conditions aren’t true, I’m 100% sure the conditions are true before saving.
Hope someone can help me on this or have some solution for saving data in a reserver server when server is shutting down.
this might happen because you teleport people before you save their data. Apperantly you are litterary teleporting everyone to other server without saving their data before the server closes, because when you teleport a player the server closes after some seconds. You need to upgrade ur code.
PleayerRemoved is used normally but when server shutdown you should use this function to save player data corretly, since PlayerRemoved When Server restart does not work / fire.