My code chooses a random map and then teleports users from a lobby team onto the two spawns on the map.
The players are randomly teleported. How can I change their teams without making the spawns "Allow team change on touch"? The teams should also be balanced.
After the round ends, how can I teleport them back to the lobby as well?
Thanks!
local replicatedstorage = game:GetService("ReplicatedStorage")
local status = replicatedstorage:WaitForChild("StatusValue")
while true do
------------------------
-- || INTERMISSION || --
------------------------
for i = 50,0,-1 do
status.Value = "Intermission: "..i
wait(1)
end
status.Value = "Choosing map"
wait (7)
local maps = game.ServerStorage.Maps:GetChildren()
local storage = workspace.MapStorage
storage:Clone().Parent = workspace
local random_map = maps[math.random (1, #maps)]
random_map:Clone().Parent = storage
status.Value = "Map Chosen: " .. random_map.Name
wait (5)
----------------------
-- || TELEPORTER || --
----------------------
spawns = random_map.Spawns:GetChildren()
for i, v in pairs(game.Players:GetPlayers()) do
name = v.Name
check = game.Workspace:FindFirstChild(name)
if check then
humanoid = check:FindFirstChild("UpperTorso")
if humanoid then
check:MoveTo(spawns[i].Position)
end
end
end
status.Value = "Game in progress"
wait (420) -- 7 Minute Round
game.Workspace.MapStorage:Destroy()
status.Value = "Game Over!"
end

5 comments
Thanks for the reply. How would I do this with more than one player?
Use 'game.Players:GetPlayers()'. That method returns an table of players, so you can just loop through the table.
One more thing, because the server will have multiple players, how would I change the players' teams so that they are balanced?
Make each team have #players divided by #teams (perform 'math.floor()' on it so it is a whole number). To get the remaining players, divide using '%' instead of '/'. Then go through the remaining players and stick them in different teams. It's a bit complicated.
Ok, thanks.