Opening and Closing Scoreboard broken

Hi there and thanks for stopping by, now lets get to it.

I am trying to make my scoreboard open and close using the GM:ScoreboardShow and Hide hooks. However the scoreboard only shows up and does not go away.

My Code is as follows



surface.CreateFont( "OverSbNorm", {
	font = "BigNoodleTitling",
	size = 30,
	weight = 500,
	antialias = true,
} )
--Making a section for colors
local bgblack = Color(65, 74, 76)
local white = Color(248, 248, 255)


local igroups = {"superadmin"}



function OverSb (open, close)

	Base = vgui.Create("DFrame")
	Base:SetPos( (ScrW()/2) - 400, 100)
	Base:SetTitle("")
	Base:SetSize(800,800)
	Base:ShowCloseButton(false)
	Base.Paint = function()
		draw.RoundedBox( 8, 0, 0, 800, 800, Color( 0, 0, 0, 0 ) )
	end

	
	local StartY = 0 
	
	for k, v in pairs(player.GetAll()) do
		 
		local PlayerPlate = vgui.Create( "DLabel", Base )
		PlayerPlate:SetPos(0, StartY)
		PlayerPlate:SetText("")
		PlayerPlate:SetSize(800, 45)
		PlayerPlate:IsDraggable(false)
		PlayerPlate.Paint = function()
			draw.RoundedBox( 8, 0, 0, 800, 45, bgblack )
		end

		local Avatar = vgui.Create( "AvatarImage", PlayerPlate )
		Avatar:SetSize( 32, 32 )
		Avatar:SetPos( 5, 7 )
		Avatar:SetPlayer( LocalPlayer(), 32 )
		StartY = StartY + PlayerPlate:GetTall() + 11

		local NameP = vgui.Create("DLabel", PlayerPlate)
		NameP:SetPos(44, 7)
		NameP:SetSize(100,32)
		NameP:SetText(v:Nick())
		NameP:SetFont("OverSbNorm")
		NameP.Paint = function()
			draw.RoundedBox( 8, 0, 0, 100, 32, Color(0,0,0,0) )
		end

		local MKarma = vgui.Create("DLabel", PlayerPlate)
		MKarma:SetPos(535,14)
		MKarma:SetFont("OverSbNorm")
		MKarma:SetText(v:GetBaseKarma())

		local MKills = vgui.Create("DLabel", PlayerPlate)
		MKills:SetPos(625,14)
		MKills:SetFont("OverSbNorm")
		MKills:SetText(v:Frags().."")

		local MDeaths = vgui.Create("DLabel", PlayerPlate)
		MDeaths:SetPos(685,14)
		MDeaths:SetFont("OverSbNorm")
		MDeaths:SetText(v:Deaths().."")


		local MPing = vgui.Create("DLabel", PlayerPlate)
		MPing:SetPos(755,14)
		MPing:SetFont("OverSbNorm")
		MPing:SetText(v:Ping().."")

		local Group = vgui.Create("DImage", PlayerPlate)
		Group:SetPos(165, 7)
		Group:SetSize(32,32)
		Group:SetImage("icons32/group.png")

		local Karma = vgui.Create("DImage", PlayerPlate)
		Karma:SetPos(505, 7)
		Karma:SetSize(32,32)
		Karma:SetImage("icons32/karma.png")

		local Kills = vgui.Create("DImage", PlayerPlate)
		Kills:SetPos(585, 7)
		Kills:SetSize(32,32)
		Kills:SetImage("icons32/kills.png")

		local Death = vgui.Create("DImage", PlayerPlate)
		Death:SetPos(650, 7)
		Death:SetSize(32,32)
		Death:SetImage("icons32/deaths.png")


		local Pings = vgui.Create("DImage", PlayerPlate)
		Pings:SetPos(715, 7)
		Pings:SetSize(32,32)
		Pings:SetImage("icons32/ping.png")

		local Rank = vgui.Create("DLabel", PlayerPlate)
		Rank:SetPos(200, 7)
		Rank:SetSize(100,32)
		Rank:SetText(v:GetUserGroup())
		Rank:SetFont("OverSbNorm")
		Rank.Paint = function()
			draw.RoundedBox( 8, 0, 0, 100, 32, Color(0,0,0,0) )
		end
		for i, _ in pairs(igroups) do
			if _ == v:GetUserGroup() then
				Rank:SetTextColor(Color(248,10,10))
			end
		end

	end
	if (close) then
		Base:Close()
	end
	if (open) then
		Base:Show()
	end
end
function CloseSb ()
	OverSb(false, true)
end
function OpenSb ()
	OverSb(true, false)
end	
hook.Add("ScoreboardShow", "OverSb", OpenSb)
hook.Add("ScoreboardHide", "COverSb", CloseSb)




Any solutions, thanks in advance!

Nobody?

Just use SetVisable(bool).

The problem is that you create the frame BEFORE actually checking whether to show or hide the frame

[editline]17th August 2016[/editline]

Try something like this:



surface.CreateFont( "OverSbNorm", {
	font = "BigNoodleTitling",
	size = 30,
	weight = 500,
	antialias = true,
} )

local bgblack = Color(65, 74, 76)
local white = Color(248, 248, 255)
local Base
local igroups = {"superadmin"}

local function OpenSb()

	Base = vgui.Create("DFrame")
	Base:SetPos( (ScrW()/2) - 400, 100)
	Base:SetTitle("")
	Base:SetSize(800,800)
	Base:ShowCloseButton(false)
	Base.Paint = function()
		draw.RoundedBox( 8, 0, 0, 800, 800, Color( 0, 0, 0, 0 ) )
	end
	
	local StartY = 0 
	
	for k, v in pairs(player.GetAll()) do
		 
		local PlayerPlate = vgui.Create( "DLabel", Base )
		PlayerPlate:SetPos(0, StartY)
		PlayerPlate:SetText("")
		PlayerPlate:SetSize(800, 45)
		PlayerPlate:IsDraggable(false)
		PlayerPlate.Paint = function()
			draw.RoundedBox( 8, 0, 0, 800, 45, bgblack )
		end

		local Avatar = vgui.Create( "AvatarImage", PlayerPlate )
		Avatar:SetSize( 32, 32 )
		Avatar:SetPos( 5, 7 )
		Avatar:SetPlayer( LocalPlayer(), 32 )
		StartY = StartY + PlayerPlate:GetTall() + 11

		local NameP = vgui.Create("DLabel", PlayerPlate)
		NameP:SetPos(44, 7)
		NameP:SetSize(100,32)
		NameP:SetText(v:Nick())
		NameP:SetFont("OverSbNorm")
		NameP.Paint = function()
			draw.RoundedBox( 8, 0, 0, 100, 32, Color(0,0,0,0) )
		end

		local MKarma = vgui.Create("DLabel", PlayerPlate)
		MKarma:SetPos(535,14)
		MKarma:SetFont("OverSbNorm")
		MKarma:SetText(v:GetBaseKarma())

		local MKills = vgui.Create("DLabel", PlayerPlate)
		MKills:SetPos(625,14)
		MKills:SetFont("OverSbNorm")
		MKills:SetText(v:Frags().."")

		local MDeaths = vgui.Create("DLabel", PlayerPlate)
		MDeaths:SetPos(685,14)
		MDeaths:SetFont("OverSbNorm")
		MDeaths:SetText(v:Deaths().."")


		local MPing = vgui.Create("DLabel", PlayerPlate)
		MPing:SetPos(755,14)
		MPing:SetFont("OverSbNorm")
		MPing:SetText(v:Ping().."")

		local Group = vgui.Create("DImage", PlayerPlate)
		Group:SetPos(165, 7)
		Group:SetSize(32,32)
		Group:SetImage("icons32/group.png")

		local Karma = vgui.Create("DImage", PlayerPlate)
		Karma:SetPos(505, 7)
		Karma:SetSize(32,32)
		Karma:SetImage("icons32/karma.png")

		local Kills = vgui.Create("DImage", PlayerPlate)
		Kills:SetPos(585, 7)
		Kills:SetSize(32,32)
		Kills:SetImage("icons32/kills.png")

		local Death = vgui.Create("DImage", PlayerPlate)
		Death:SetPos(650, 7)
		Death:SetSize(32,32)
		Death:SetImage("icons32/deaths.png")


		local Pings = vgui.Create("DImage", PlayerPlate)
		Pings:SetPos(715, 7)
		Pings:SetSize(32,32)
		Pings:SetImage("icons32/ping.png")

		local Rank = vgui.Create("DLabel", PlayerPlate)
		Rank:SetPos(200, 7)
		Rank:SetSize(100,32)
		Rank:SetText(v:GetUserGroup())
		Rank:SetFont("OverSbNorm")
		Rank.Paint = function()
			draw.RoundedBox( 8, 0, 0, 100, 32, Color(0,0,0,0) )
		end
		for _, group in pairs(igroups) do
			if group == v:GetUserGroup() then
				Rank:SetTextColor(Color(248,10,10))
			end
		end

	end
	
end

local function CloseSb()
	if IsValid( base ) then base:Remove() end
end

hook.Add("ScoreboardShow", "OverSb", OpenSb)
hook.Add("ScoreboardHide", "COverSb", CloseSb)


I feel like a dunce for not validating my panels :pudge:
Thanks so much for helping