why is my gamemode not working how it should?

so what my gamemode should do is start a new round and every one spawns in team 1 apart from 1 random player who goes to team 2, when the player dies they go as a Spectater and they should start a new round if all red team dies or if all blue team dies

but when i tested it with a friend we both only went to team one and non of us where team 2

can i get some help plz

(btw this is my first gamemode so sorry for being a noob)


AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")
include("player.lua")

util.AddNetworkString("RoundStatus")
util.AddNetworkString("WhoWon")
util.AddNetworkString("EndOfRound")

GM.RoundStatus = 0
GM.WhoWon = 0
--[[
	0 - Not enough players
	1 - Active Round
	2 - Round Ended; restarting
]]--

function GM:GetRoundStatus()
	return self.RoundStatus or 0
end

function GM:SetRoundStatus(roundstatus)
	self.RoundStatus = roundstatus
	if roundstatus == 1 then return end
	self:Networking()
end

function GM:Networking(ply)
	net.Start("RoundStatus")
		net.WriteInt(self.RoundStatus, 32)
	net.Broadcast()
	net.Start("WhoWon")
		net.WriteInt(self.WhoWon, 32)
	net.Broadcast()
end

function GM:RoundThink()
	local blue = team.GetPlayers(1)
	local red = team.GetPlayers(2)
	local players = player.GetAll()
	
	RoundStatus1 = self.RoundStatus
	
	if self.RoundStatus == 0 then 
		if #players > 1 then
			self:StartNewRound()
		end
	end
	if self.RoundStatus == 1 then
		self:CheckStatus()
	--	print("Active Round 1")
	elseif self.RoundStatus == 2 then
		if #players <=1 then 
			self:SetRoundStatus(0)
		else
			self:EndOfRound()
		end
	end
end
--[[
	0 - No one won
	1 - blue won
	2 - red won
]]--
function GM:CheckStatus()
	local blue = team.GetPlayers(1)
	local red = team.GetPlayers(2)
	
	
	
	-- print("Called")
	if #blue <= 0 then
		self.WhoWon = 2
		self:SetRoundStatus(2)
		print("red Won!")
		PrintMessage( HUD_PRINTTALK, "The red won! The red was " .. redselect:Nick() )
	elseif #red <=0 then
		self.WhoWon = 1
		self:SetRoundStatus(2)
		print("blue Won!")
		PrintMessage( HUD_PRINTTALK, "blue Won! The red was " .. redselect:Nick() or "Error")
	end
end

function GM:StartNewRound()
PrintMessage( HUD_PRINTTALK, "Round Starts" )
	for k, v in pairs(player.GetAll()) do
		v:SetGamemodeTeam( 1 )
		v:UnSpectate()
		v:Spawn()
		
	end
	
local tInd = 1
local tPlyUnsel = team.GetPlayers(tInd)
local tPly_count = #tPlyUnsel
for i = 0, math.floor(math.abs(tPly_count - 1) / 4) do
    -- Note: 4 is multiplier for players' count
    local chPly, chID = table.Random(tPlyUnsel) -- chPly identifies the chosen one player object, chID gives ID of player
	chPly:SetGamemodeTeam( 2 )
	print(chPly:Nick() ..  " Has been made the red!")
	timer.Simple( 15, function() chPly:Give("weapon_smg1") end )
	timer.Simple( 15, function() self:SetRoundStatus(1) end ) 
    table.remove(tPlyUnsel, chID)
	
	for i=1,1 do
		game.CleanUpMap()
	end
	self:StartRound()
end
end

function GM:EndOfRound()
	if timer.Exists("EndOfRound") then return end
    timer.Create( "EndOfRound", 10 , 1, function()
        if !self.RoundStatus == 2 then return end
			self:StartNewRound()
			print("Working...")
    end )
	
	if timer.Exists("EndOfRoundSound") then return end
	timer.Create( "EndOfRoundSound", 0, 1, function()
		if !self.RoundStatus == 2 then return end
			for k,v in pairs(player.GetAll()) do
				local pitch = math.random(80, 120)
				v:EmitSound("ambient/alarms/warningbell1.wav", 100, pitch)
			end
			net.Start("EndOfRound")
				net.WriteInt(1, 32)
			net.Broadcast()
			
	end)
	
end 

function GM:PlayerSpawn( ply )
	ply:SetModel("models/player/group01/male_07.mdl")
	ply:SetGamemodeTeam( 1 )
	self.BaseClass:PlayerSpawn( ply )
   
    ply:SetMaxHealth( 100, true )  
	ply:SetJumpPower( 300 )
 
    ply:SetWalkSpeed( 220 )  
    ply:SetRunSpeed ( 300 )
	
	end
 
 function GM:PlayerDeathThink(ply)
    ply:SetMoveType(MOVETYPE_FLY)
    ply:Spectate(OBS_MODE_ROAMING)
end
 
hook.Add( "PlayerDeath", "playerDeathTest", playerDies )




No offense, but I don’t think you understand much about Lua. This is the exact same code somebody posted in another thread you made, just slightly edited. You should try to learn more about Lua before making a gamemode. Try making a weapon, perhaps.

Anyway, do you get any errors in the console? Judging by the bit of code you posted, you aren’t setting the team anywhere, so it defaults to 1.

oh i can make weapons fine

and yeah lua is funny with me but i get there but i am learning like 3 coding languages in my college course so you know

but i get no errors any suggestion on what to change tho?

SetGamemodeTeam isn’t a function unless you made a custom function for setting teams.

If not, you should be using “SetTeam” not “SetGamemodeTeam”.

right i will change it to that then i well give it a test when i can with a friend and let you know