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
There are two ways to change teams.
The first is to change the player's TeamColor
property to that of a corresponding TeamColor
in a team.
Note that to set the player's team using TeamColor
, you may need to disable the Neutral
property of the player first.
The second is to set the player's Team
property to the corresponding Team
object in the Teams
service.
-- TeamColor Player.Neutral = false Player.TeamColor = game.Teams.Team1.TeamColor -- Team Player.Team = game.Teams.Team1
You can also set the player's RespawnLocation
property to a specific SpawnLocation
so that the next time their character spawns, that will be the location they spawn at.
Player.RespawnLocation = game.Workspace.SpawnLocation
Hope I helped!
~TDP