UpdateAsync sometimes not firing for no reason

I’m trying to make an inventory system, and everything within UpdateAsync just doesn’t fire at all sometimes, even though the print just before it works just fine.
image

I’ve even tried putting it in a while loop that only stops when it’s fired, and that STILL doesn’t fire UpdateAsync 100% of the time.

Have you Tried Adding a BindToClose() set up. What I am assuming is that is datastore UpdateAsync() is on player removing. But sometimes the server shuts down before PlayerRemoving Can be called. If you are using PlayerRemoving. I recommend Adding BindToClose(). There is an issue is that also it sometimes can be Fired twice (Because of player removing, and BindToClose being called before they fully left). This can be fixed By Making a table of all the players who have saved their data, and once fully done, remove them from the list (in case of rejoining the same server).

Here is a basic Set up on BindToClose() for datastores with a debounce as mentioned above:

local ListOfPlayers = {}
local function SaveData(Player)
if table.find(ListOfPlayers, Player.Name) then return end
table.insert(ListOfPlayers, Player.Name)

--Code To Save Data

repeat task.wait() until game.Players:FindFirstChild(Player.Name) == nil
table.remove(ListOfPlayers, table.find(ListOfPlayers, Player.Name))
end

game:BindToClose(function()
	for i, v in game.Players:GetPlayers() do
			coroutine.wrap(SaveData)(v)
		end
	
end)