My First Game! Help on my round based system

I am trying to achieve a round based system and make it efficient. I want to have 3 Teams a Red Team, Blue Team, and Lobby Team. There will be an intermission countdown, then it will say ‘Starting Game’ after that the players will be switched to there teams and reloaded to their spawn-points.

My current script involves values located in the workspace that switch true or false and a int value that gives the gui value. I used a lot of while loops and I believe there is a more effceit way to do what I am trying to do I just can’t figure it out.

local status = game.workspace.MainSystem.GuiStat
local rTeam = game.Teams.Red
local bTeam = game.Teams.Blue									 
local Players = game:GetService("Players") 
local TablePlay = game.Players
local TablePlay2 = game.Players:GetChildren()


local function teamUp() --Funtion to Change Team

for i, v in pairs(TablePlay:GetChildren()) do --loop through table

    if i % 2 == 0 then --if even number

       print(v) --Will Be a Team
		v.Team = bTeam

    else 
		v.Team = rTeam	--Will Be a Team
end
end
end
		
while true do
while InGame.Value == false and status.Value > 0 do --Intermission since InGame is False
	wait(1)
	status.Value = status.Value - 1
	end
	if status.Value == 0 then
		InGame.Value = true
		status.Value = 10	
		end
		
	while InGame.Value == true and status.Value > 0 do --Game in progress since InGame is True
	wait(1)
	status.Value = status.Value - 1 --Countdown
	if InGame.Value == true then
		teamUp() --Teans Player
		end
  	
		
	
			
end

I really want to become a very efficient scripter and learn more everyday. Thanks your your help!

Indenting code is really essential when getting support on it.

What I would do:
Don’t have a lobby team and just set the player to Neutral until the game starts.

You did:

local Players = game:GetService("Players") 
local TablePlay = game.Players
local TablePlay2 = game.Players:GetChildren()

First off, Players and TablePlay are the same thing basically; you should get rid of TablePlay. For TablePlay2, do

local Players = game:GetService("Players") 
local TablePlay = Players:GetPlayers()

Instead.

Your code using correct indentation:

local status = game.workspace.MainSystem.GuiStat
local rTeam = game.Teams.Red
local bTeam = game.Teams.Blue									 
local Players = game:GetService("Players") 
local TablePlay = game.Players
local TablePlay2 = game.Players:GetChildren()


local function teamUp() --Funtion to Change Team

    for i, v in pairs(TablePlay:GetChildren()) do --loop through table

        if i % 2 == 0 then --if even number

            print(v) --Will Be a Team
		    v.Team = bTeam

        else 
		    v.Team = rTeam	--Will Be a Team
        end
    end
end

while true do
    while InGame.Value == false and status.Value > 0 do --Intermission since InGame is False
	    wait(1)
	    status.Value = status.Value - 1
	end
	if status.Value == 0 then
		InGame.Value = true
		status.Value = 10	
    end
		
	while InGame.Value == true and status.Value > 0 do --Game in progress since InGame is True
	    wait(1)
	    status.Value = status.Value - 1 --Countdown
	    if InGame.Value == true then
		    teamUp() --Teans Player
		end	
end

Getting the players dosen’t work when I set the teams. You have to get the children.

Getting the players is basically the same exact thing as getting the children.

As @IAmPinleon said, this is bad practice.

This won’t work as planned, because when you declare TablePlay at the beginning of the script it will be empty as there are no players in game yet. You should instead get the current playerlist,
for index, players in pairs(game.Players:GetChildren()) do

Yea I know, I did try getting player but it didn’t seem to work so I just used children.