Hello! I have data that saves when the game closes down, and I have used this same script for many games and it has worked! However, recently when I ran this in a new game this error popped up: 09:07:33.908 BindToClose failed because the model is already being closed.

Here is my code:

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("Tokens")

game.Players.PlayerRemoving:Connect(function()
	local function saveData(player)
		local stats = player.leaderstats

		local tokens = stats.Tokens

		local tries = 0
		local success
		repeat
			tries = tries + 1
			success = pcall(function()
				DS:SetAsync(player.UserId,{
					tokens = tokens.Value,
				})
			end)
			if not success then
				wait(1)
			end
		until tries == 5 or success
		if not success then
			warn("Cannot save data for "..player.Name.."!")
		end
	end

	game.Players.PlayerRemoving:Connect(function(player)
		saveData(player)
	end)

	game:BindToClose(function()
		print("noooo")
		for i,v in pairs(game.Players:GetPlayers())do
			saveData(v)
		end
	end)

end)

I have searched all over and this is the only other post I found on this, and it is on the devforum: https://devforum.roblox.com/t/bindtoclose-failed-because-the-model-is-already-being-closed/141210

I am really stumped because I have never seen this before. Is there anybody that knows a fix? Is it in game settings or something? I have been scripting for about 2 years and this has never happened, thanks!