so can i get some help?

can some one help me plz i cant find my this dosent like this

sorry for noobness


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

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

local round = {}

-- Variables
round.Break	= 30	-- 30 second breaks
round.Time	= 300	-- 5 minute rounds

function round.Broadcast(Text)
	for k, v in pairs(player.GetAll()) do
		v:ChatPrint(Text)
	end
end

function round.Begin()
	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)
    table.remove(tPlyUnsel, chID)
end
	
	round.Broadcast("Round starting! Round ends in " .. round.Time .. " seconds!")
	timer.Simple(round.Time, round.End)
end

function round.End()
	-- Your code
	-- (Anything that may need to happen when the round ends)
	
	round.Broadcast("Round over! Next round in " .. round.Break .. " seconds!")
	timer.Simple(round.Break, round.Begin)
end

round.Begin()

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 ) 

“i get the error”

[ERROR] gamemodes/troubleinstarwars/gamemode/init.lua:38: attempt to index local ‘chPly’ (a nil value)

  1. unknown - gamemodes/troubleinstarwars/gamemode/init.lua:38

Couldn’t Load Init Script: ‘troubleinstarwars/gamemode/init.lua’

If team.GetPlayers returns an empty table, then table.Random is going to return nil. You’ll need to perform a check on the player count. This is probably what’s causing your error.

Last time you said that team change doesn’t seem to work when you’re calling “chosen one” snippet. Is it exactly do not work when you call “chosen one” or every time you call “SetGamemodeTeam”? I don’t see anywhere your custom method “SetGamemodeTeam”, so I can’t say what’s wrong.