So I have this fragment of a script here. For some reason, table.remove isn't functioning.
The output says: "bad argument #2 to 'remove' (number expected, got string)
playersnotplaying = {} for i,v in pairs(game.Players:GetChildren()) do table.insert(playersnotplaying, v.Name) end randomplayer = playersnotplaying[math.random(1, #playersnotplaying)] for i,v in pairs(playersnotplaying) do table.remove(playersnotplaying, randomplayer) end
I don't understand why this isn't functioning properly.
table.remove has two arguments; the table itself, and the numerical index that you want to remove. To fix your code, use the following:
playersnotplaying = Game.Players:GetPlayers() --This is exactly the same as what you were doing. This is nothing to do with the error, just more efficient. randomIndex = math.random(1, #playersnotplaying) randomplayer = playersnotplaying[randomIndex] table.remove(playersnotplaying, randomIndex) --Remove the index where randomplayer is located.