Hey there, so i have a folder of teams in server storage, and i have a game script that loads in a map, and then teleports the players to that map. BUT i want it to also load in the teams if its a map that is a team game, here is my code.
local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('StatusValue')
local serverstorage = game:GetService('ServerStorage')
local GamesFolder = game.ServerStorage.Games
local TeamsFolder = game.ServerStorage.Teams
local AvailableTeams = TeamsFolder:GetChildren()
local TeamService = game:GetService('Teams')
t = 30
repeat
t = t-1
status.Value = "Intermission.. " ..t
wait(1)
until t == 0
status.Value = "Choosing Game, please wait."
wait(5)
local AvailableGames = GamesFolder:GetChildren() -- Gets all the available games
local ChosenMap = AvailableGames[math.random(1, #AvailableGames)] -- Chooses a random game from the table
print(ChosenMap)
local ClonedGame = ChosenMap:Clone()
ClonedGame.Parent = workspace
if ChosenMap.Name == "Doom Spire Team Brick Battle" then
AvailableTeams.Parent = TeamService
end
status.Value = "The Next Game is "..ChosenMap.Name.."!"
wait(5)
status.Value = "Teleporting Players..."
wait(2)
local SpawnPoints = ClonedGame:FindFirstChild("SpawnPoints")
local AvailableSpawnPoints = SpawnPoints:GetChildren()
if not SpawnPoints then
print("Spawnpoints not found!")
end
local plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player)
end
end
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
-- Teleport Them
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
print("Player Teleported")
table.remove(AvailableSpawnPoints, 1)
else
if not player then
table.remove(plrs,i)
end
end
end
end
How do i go about this? Also my script is in serverscriptservice if that helps.

1 comment
Maybe try an if statement to check if the name of the map a certain name for teams or maybe try adding a intvalue in the map to use as reference like if IntValue == 1 then only do 1 team, but if you aren't going to have that many maps it may be easier to just use the specific map name to determine teams