How to remove instance from table?

Heya! So at the moment I’m trying to teleport players at different spawn points, I did this by adding this by adding each spawn part into a table. When I try to remove it from the table I get an error.

 ServerScriptService.Modules.GameFunctions:41: invalid argument #2 to 'remove' (number expected, got Instance)

What did I do wrong and how can I fix this?

function GameFunction.TeleportPlayers(Map, Table)
	local Spawns = Map.Spawns:GetChildren()
	local SpawnLocations = {}
	for i = 1, #Spawns do
		table.insert(SpawnLocations, Spawns[i])

	for i, v in ipairs(Table) do
		local Player = v
		local PlayerSpawn = SpawnLocations[math.random(1, #SpawnLocations)]
		Player.Character.HumanoidRootPart.CFrame = PlayerSpawn.CFrame
		table.remove(SpawnLocations, PlayerSpawn)
1 Like

For table.remove you need to use the index of the instance you’re trying to remove.

Here’s an example of what you could do:

table.remove(SpawnLocations, table.find(SpawnLocations, PlayerSpawn))

I think this works.