"invalid argument #2 to 'remove' (number expected, got Instance)"

Hello developers,

I am currently experiencing an issue with a script that is attempting to remove a player from a table. I cant find the issue within this. Any help would be appreciated!

Also the issue is on line 23. The output reads out “invalid argument #2 to ‘remove’ (number expected, got Instance)”

local playerscurrentlyinround = {}

while wait() do

	for i, plr in pairs(game.Players:GetPlayers()) do
		if plr:FindFirstChild("Contestant") then
			if not table.find(playerscurrentlyinround, plr) then
				table.insert(playerscurrentlyinround, plr)
			end	
		end
	end
	

	for i, plr in pairs(game.Players:GetPlayers()) do
		if plr:FindFirstChild("Contestant") then
			if plr:FindFirstChild("Escaped") then
				if table.find(playerscurrentlyinround, plr) then
					table.remove(playerscurrentlyinround, plr)
				end	
			end	
		else
			if table.find(playerscurrentlyinround, plr) then
				table.remove(playerscurrentlyinround, plr) -- ISSUE IS HERE
			end	
		end
	end

	game.ReplicatedStorage.GetPlayersForBar.OnServerEvent:Connect(function(players)
		script.Parent.PlayerAmount.Value = #playerscurrentlyinround
	end)

	script.Parent.Amount.Text = ""..#playerscurrentlyinround.."/"..script.Parent.PlayerAmount.Value..""

end
1 Like

table.remove's second parameter is the index of the object, not the object itself.
You can get the index with table.find.

2 Likes

Use table.find to get the index of the plr:

table.remove(playerscurrentlyinround, table.find(playerscurrentlyinround,plr))
2 Likes