Group sorting in the scoreboard

Hello. I’m the first time at this forum(my eng is the best). So, I made a scoreboard and I need group sorting using UTeams. Help.
Here is a code of scoreboard



if SERVER then
	print("Scoreboard: I'M LOADED")
end

local function GetTeamName( check_group )
	for _, team in ipairs(ulx.teams) do
		for _, group in ipairs(team.groups) do
			if group == check_group then
				return team.name
			end
		end
	end
	return check_group
end

local function DiffColor(clr)
    local r,g,b,a = clr.r,clr.g,clr.b,clr.a
    if r>100 then r = r - 100 else r = r + 100 end
    if g>100 then g = g - 100 else g = g + 100 end
    if b>100 then b = b - 100 else b = b + 100 end
    return Color(r,g,b,a)
end

local ScoreboardDerma = nil;
hook.Add("ScoreboardShow", "My_Scoreboard", function()
	if !IsValid(Scoreboard) then
		ScoreboardDerma = vgui.Create("DFrame")
		ScoreboardDerma:SetSize(900, 500)
		ScoreboardDerma:SetPos(ScrW() / 2 - 450, ScrH() / 2 - 250)
		ScoreboardDerma:SetTitle("")
		ScoreboardDerma:SetDraggable(false)
		ScoreboardDerma:ShowCloseButton(false)
		ScoreboardDerma.Paint = function()
			draw.RoundedBox(5, 0, 0, ScoreboardDerma:GetWide(), ScoreboardDerma:GetTall(), Color(60, 60, 60, 255))
		end

		local ScrollPanel = vgui.Create("DScrollPanel", ScoreboardDerma)
		ScrollPanel:SetSize(ScoreboardDerma:GetWide(), ScoreboardDerma:GetTall())
		ScrollPanel:SetPos(0,0)

		PlayerList = vgui.Create("DListLayout", ScrollPanel)
		PlayerList:SetSize(ScrollPanel:GetWide(), ScrollPanel:GetTall())
		PlayerList:SetPos(0,0)
	end

	if IsValid(ScoreboardDerma) then
		PlayerList:Clear()

		for k,v in pairs(player.GetAll()) do
			local PlyPnl = vgui.Create("DPanel", PlayerList)
			PlyPnl:SetSize(PlayerList:GetWide(), 32)
			PlyPnl:SetPos(0,0)
			PlyPnl:SetBackgroundColor(GAMEMODE:GetTeamColor(v))

			local AvatarImage = vgui.Create("AvatarImage", PlyPnl)
			AvatarImage:SetSize(32,32)
			AvatarImage:SetPos(0,0)
			AvatarImage:SetPlayer(v, 32)

			local AvatarImageButton = vgui.Create("DButton", AvatarImage)
			AvatarImageButton:SetSize(32,32)
			AvatarImageButton:SetPos(0,0)
			AvatarImageButton:SetText("")
			AvatarImageButton.Paint = function()
				draw.RoundedBox(0,0,0,AvatarImage:GetWide(),AvatarImage:GetTall(),Color(0,0,0,0))
			end
			AvatarImageButton.DoClick = function()
				v:ShowProfile()
			end

			local PlText = vgui.Create( "DLabel", PlyPnl )
		    PlText:SetPos( 36, 0 )
		    PlText:SetText( v:GetName() )
		    PlText:SetFont('DermaLarge')
		    PlText:SetColor(DiffColor(GAMEMODE:GetTeamColor(v)))
		    PlText:SizeToContents()

		    local PlGroup = vgui.Create("DLabel", PlyPnl)
		    PlGroup:SetPos( PlyPnl:GetWide() - 325, 0 )
		    PlGroup:SetText( GetTeamName(v:GetUserGroup()) )
		    PlGroup:SetFont('DermaLarge')
		    PlGroup:SetColor(DiffColor(GAMEMODE:GetTeamColor(v)))
		    PlGroup:SizeToContents()

		    local PlPing = vgui.Create("DLabel", PlyPnl)
		    PlPing:SetPos( PlyPnl:GetWide() - 30, 0 )
		    PlPing:SetText(v:Ping())
		    PlPing:SetFont('DermaLarge')
		    PlPing:SetColor(DiffColor(GAMEMODE:GetTeamColor(v)))
		    PlPing:SizeToContents()
		end
		ScoreboardDerma:Show()
		ScoreboardDerma:MakePopup()
		ScoreboardDerma:SetKeyboardInputEnabled(false)
	end
	return true
end)

hook.Add("ScoreboardHide", "My_Scoreboard", function()
	if IsValid(ScoreboardDerma) then
		ScoreboardDerma:Hide()
	end
	return true
end)