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
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.