So In my script when Player Removing fires I save a value and set that value to nil right after
But I don't see a point on BindToClose if BindToClose is going to fire after Player Removing is going to save since it fires first
BindToClose can be used in many scenarios. For example, let;s say you want to be informed when a server shuts down. And you want to know how/when it shut down. BindToClose makes this quite easy.
Here's a quick example:
local Players = game:GetService("Players"); local DataStoreService = game:GetService("DataStoreService"); local LogDS = DataStoreService:GetDataStore("Log"); local function gameClosing() local Data = nil; if (#Players:GetPlayers() > 0) then Data = "server shut down for some random reason"; elseif (#Players:GetPlayers() == 0) then Data = "everyone eventually left"; end; LogDS:UpdateAsync(game.JobId,function(old) return Data; end); end; game:BindToClose(gameClosing);
(I have not tested this)