Spawnpoint tp problem

So this script have problem, when the get ready countdown go to 0, the map disappear and choose a random winner, I can’t find the problem, and also the script tp two players to same spawn point (name of spawnpoint is the name of mapa)

local maps = game.ReplicatedStorage.Maps
local gameTime = 90
local serverMessages = game.ReplicatedStorage.ServerMessage
local gameState = game.ReplicatedStorage.GameState
local choosenMap
local aliveFolder = game.ReplicatedStorage.PlayersAlive
local lobbyFolder = game.ReplicatedStorage.PlayersInLobby
local sword = game.ReplicatedStorage.Sword
local amt = 1

local RanMap = {“Crossroads”}

while true do
wait(1)

serverMessages.Value = "Waiting for more players"

repeat wait()until #game.Players:GetChildren() >= 2

serverMessages.Value = "Intermission"

local players = { }

game:GetService("Players").PlayerRemoving:Connect(function(plr)
	table.remove(players,table.find(players,plr)
		
	)
end)

for i,plr in pairs(game.Players:GetPlayers())do
	if plr then
		table.insert(players,plr)
	end
	end	

local random = math.random(1,table.getn(RanMap))
choosenMap = RanMap[random]
wait(25)

serverMessages.Value = choosenMap … " was chosen"
wait(3)

local NewMap = maps[choosenMap]:Clone()
NewMap.Parent = workspace
NewMap.Name = “Map”

local Number
Number = 5
for i = 1,Number do
serverMessages.Value = "Joining in "… Number
Number = Number - 1
wait(1)
end

for i, plr in pairs(players)do
	if plr then
		local character = plr.Character
		character:MoveTo(workspace:FindFirstChild("Map").Position)
	end
end

for i,PlrValues in pairs(lobbyFolder:GetChildren())do
	PlrValues.Parent = aliveFolder
end

serverMessages.Value = "Get Ready!"

wait(3)
Number = 1
for i = 1,Number do
	serverMessages.Value = "Starting In ".. Number
	Number = Number - 1
	wait(1)
end


for i, plr in pairs(players)do
	if plr then
		if aliveFolder:FindFirstChild(plr.Name)then
			plr.PlayerGui.Message.PlayersInMatch.Visible = true
			local character = plr.Character
			local NewSword = sword:Clone()
			if not plr then
				table.remove(players,o)
			end
			NewSword.Parent = character
		else
			
		end
	end
end



gameState.Value = true
wait(1)
Number = gameTime


print(#players)
-- game timer

for i = gameTime,0,-1 do
	
	for o,plr in pairs(players)do
		if plr then
			local character = plr.Character
			if not character then
			else
				if aliveFolder:FindFirstChild(plr.Name) then
				else
					table.remove(players,o)
				end
				if workspace:FindFirstChild(plr.Name)then
				else
					table.remove(players,o)
				end
			end
		else
			table.remove(players,o)
		end
	end
	serverMessages.Value = "Time Left ".. i .. " s"
	if #players == 1 then
		serverMessages.Value = players[1].Name.. " is the Winner"
		players[1].leaderstats.Wins.Value = players[1].leaderstats.Wins.Value  + amt
		break
	elseif #players == 0 then
		serverMessages.Value = "Game Over"
		break
	elseif i == 0 then 
		serverMessages.Value = "Times Up"
		break
	end
	wait(1)
end

gameState.Value = false

NewMap:Destroy()

for i, plr in pairs(players)do
	if plr then
		local character = plr.Character
		character:MoveTo(workspace.Lobby.Position)
	end
end

for i,PlrValues in pairs(aliveFolder:GetChildren())do
	PlrValues.Parent = lobbyFolder
end

for i, plr in pairs(players)do
	if plr then
		plr.PlayerGui.Message.PlayersInMatch.Visible = false
		local character = plr.Character
		if character:FindFirstChild("Sword")then
			character.Sword:Destroy()
		elseif plr.Backpack:FindFirstChild("Sword")then
			plr.Backpack.Sword:Destroy()
		end
	end
end

end

I already change map and spawn positions.

Hi, can you please use ( ``````) for all your code because it’s a bit hard to read. The reason the players teleport to the same spawn is obvious in this line.

What you could instead is create a group of spawns in the map and use math.random in a table to get a spawn, grab the player’s HumanoidRootPart, teleport them to that specific spawn and remove that spawn from the table, this is just so player’s don’t overlap when teleported. Keep in mind you need to add a Vector so they spawn a bit higher. Right now, I can’t see to find any issues regarding player winner and map, tho some of your code could definitely be simplified. I notice your code is a bit all over the place and whilst this is dependent on preferences, try to keep it so they flow of each other, this way it’s easier to understand.

Using tables instead of physical folders seems to be more efficient. When checking for In-Game players left, if a player is removed, check if there is a specified number of players left in game in the table. If you want to choose a random number from those players left in the game,

In a (Server) Script do;

local IN_GAME_PLAYERS = {}
local OUT_OF_GAME_PLAYERS = {}
local MinimumPlayerNumberToEnd = 5 -- The number of players needed to start the ending process.
local winnerStand = game.Workspace:WaitForChild("map") -- Where the player will stand after winning.

local function EndingGame()
	wait(10) -- Time Left Until round ends from last player death.
	if #IN_GAME_PLAYERS > MinimumPlayerNumberToEnd then return end
	local Winner = math.random(1, #IN_GAME_PLAYERS) -- Will choose a number from the amount of people left.

	print(IN_GAME_PLAYERS[Winner].Name) -- Will print the winners name.
	IN_GAME_PLAYERS[Winner].Character:WaitForChild("HumanoidRootPart").Position = winnerStand.Position + Vector3.new(0, 4, 0) -- Moves the player to a specified point when wins.
	-- Added + Vector3.new(0, 4, 0) so the player doesn't glitch through the part.
end

-- Starting round
for _, player in pairs (game.Players:GetPlayers()) do
	table.insert(IN_GAME_PLAYERS, #IN_GAME_PLAYERS + 1, player) -- Inserts the players into the table.
	
	repeat wait() until player.Character -- Wait until the Players Character exist.

	local function HumanoidDied()
		table.remove(IN_GAME_PLAYERS, player)
		table.insert(OUT_OF_GAME_PLAYERS, #OUT_OF_GAME_PLAYERS + 1, player)
		EndingGame() -- Begin the ending game process
		humDied:Disconnect()
	end

	local character = player.Character
	local humanoid = character.Humanoid

	humDied = humanoid.Died:Connect(HumanoidDied) -- If the humanoid dies, connect the function.

	-- You can also teleport all the players into the map from this for loop.
end

Make sure you put this inside a loop, if this is a round based game.