Is this a good way to prevent Character cannot be changed as Player (player) is being removed

I have been getting a warning quite a bit in my game that I am trying to fix:
Character cannot be changed as Player (player) is being removed.
Is this a good way to combat this warning?

local playersBeingRemoved = {}

players.PlayerRemoving:Connect(function(player)

	table.insert(playersBeingRemoved, player)
	wait(3)
	table.remove(playersBeingRemoved, table.find(playersBeingRemoved, player))

end)

--there is other code surrounding this, this is just where I believe the warning is occurring 
if #towerTeam:GetPlayers()~=0 then
			for i, v in pairs(towerTeam:GetPlayers()) do
				if not table.find(playersBeingRemoved, v) then
					incrementEvent:Fire(v, "Tower")
					
					v.Team=spectatorsTeam
					v.Character:PivotTo(CFrame.new(math.random(-30,30), 288, math.random(-220, -180))) 
					if v.Character:FindFirstChild("Highlight") then
						v.Character.Highlight:Destroy()
					end
				end
			end
		end

if i were you i would just use a pcall but idk if thats the best option im not that experienced

It is in a xpcall but the problem is this is a warning not an error so xpcall doesn’t catch it. I don’t even know if this is yielding my script or what script the warning is coming from. I couldn’t find a single other reference of someone else mentioning this warning message.

warnings dont yield lol its just print but yellow

1 Like

I still would like to know whether this warning is my fault or not

well if its because of the player leaving then i dont think so

When the player is being removed, the player will get instantly removed from GetPlayers()
So the warning is probably somewhere else

Instead of changing the Character of a player that’s being removed, why don’t you just duplicate their character and change that clone?