I can't figure out why this part in my script isn't working when it tries to teleport all players to the map. What it does is insert all the players into a table then I use a for loop to get all the players in the table. Then, whenever I assign each player a spawn to be teleported to, it just doesn't teleport them and gives no error.
--insert players into table for _, player in pairs(game.Players:GetPlayers()) do table.insert(_G.gamePlayers, player) end --teleport players for _, player in pairs(_G.gamePlayers) do local spawns = randomMap:FindFirstChild("Spawns"):GetChildren() if #spawns > 0 then local head = player.Character:FindFirstChild("Head") local allSpawns = spawns[math.random(1, #spawns)] local randomSpawn = table.remove(spawns, math.random(#spawns)) if head and randomSpawn then head.CFrame = CFrame.new(randomSpawn.Position + Vector3.new(0, 2, 0)) end end end
Instead of lines 4-12 just use table.remove on the global table to remove the player that died.
-- Im on mobile so excuse my lack of indentation for i, v in pairs (_G.gamePlayers) do if v == player then table.remove(_G.gamePlayers, i) end end