Bad argument, number expected

So I am making a table,

for i,v in pairs(game.Players:GetPlayers()) do
	if v then
	if v:FindFirstChild("Val") then
		table.insert(plrsGame,v)
			else
		table.remove(plrsGame,v) -- The issue is here, it doesn't remove them (aka Line 62)
			
	end
end

The error in output is:

17:28:43.540 - ServerScriptService.CoreScript.RoundMod:62: bad argument #2 (number expected, got Object)

I have also tried:

  for i,v in pairs(game.Players:GetPlayers()) do
	if v then
	if v:FindFirstChild("Val") then
		table.insert(plrsGame,v)
			else
if not v:FindFirstChild("Val") then
		table.remove(plrsGame,v)
			end
	end
end

But still won’t register

Any help on fixing this?

The error tells you what is wrong with it - table.remove expects a number as its second argument, being the numeric index of an entry that you’d want to remove from the table. So, you should be doing:

table.remove(plrsGame, i)

or you can do:

plrsGame[I] = nil
4 Likes

I tried that a few minutes ago, didn’t work, but now I realised it was an error later down the script that made it fail.

Thanks for the reminder!