Problem with PlayerRemoving and BindToClose events

Hello guys,
I am wondering if PlayerRemoving and BindToClose will be called and the following code will run. In studio, I can’t trigger the PlayerRemoving event.

Does these code work?

My main conern is that the folder will be nil due to the player character leaving the game first

playerService.PlayerRemoving:Connect(function(player)
	local waitForCharacter = player.Character or player.CharacterAdded:Wait()
	local playerTagsFolder = waitForCharacter:FindFirstChild("Tags")
end)
game:BindToClose(function()
for i,v in pairs(game.Players:GetPlayers()) do
      local waitForCharacter = v.Character or player.CharacterAdded:Wait()
	local playerTagsFolder = waitForCharacter:FindFirstChild("Tags")
end
end)

PlayerRemoving fires when a player leaves the game.

When you’re in studio, ensure that you leave the game through the in-game menu instead of stopping the play test. That will fire PlayerRemoving.

I have another function for auto saving player’s inventory data. Basically I want to have two systems in my game for extra protection. I don’t know whether that will be better. Auto saving works in the game but it is just the player removing event having some problem

My function for saving the player’s inventory data

local function savePlayerData(player)
	local waitForCharacter = player.Character or player.CharacterAdded:Wait()
	local savedTags = {}

	local playerTagsFolder = player:FindFirstChild("Tags")
	local playerTagsFolderChidren = playerTagsFolder:GetChildren()

	if playerTagsFolder and playerTagsFolderChidren then

		for _,items in pairs(playerTagsFolderChidren) do
			table.insert(savedTags, items.Name)

			print("Adding "..items.Name.." to "..player.Name.."'s Inventory")
		end

		local success = pcall(function()
			TagDataStore:SetAsync(player.UserId, savedTags)
		end)

		if success then
			print("Successfully saved "..player.Name.."'s Inventory data")
		else
			warn("Couldn't save "..player.Name.."'s Inventory data")
		end
	else
		warn("No Folder")
	end
end

When the player leaves, run this function

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

It printed out this but it doesn’t save the player’s inventory data

 01:21:29.381  Adding Friendly to CurryFires's Inventory  -  Server - Game:156