Derma Timer

I’m attempting to make some derma menus, but they won’t work unless I actually edit the file, I’m pretty sure I need to make a timer to load the lua file after the client has connected as I receive this error


[ERROR] lua/autorun/client/derma.lua:7: attempt to index global 'DMain' (a nil value)
  1. MyMenu - lua/autorun/client/derma.lua:7
   2. unknown - lua/autorun/client/derma.lua:34



I’ve tried creating timers in functions, out of functions everything but I can’t seem to get this working…

Derma Code:


function MyMenu()
	if IsValid(DMain) then DMain:Remove() end 
	if IsValid(closeButton) then closeButton:Remove() end 
	DMain = vgui.Create("DFrame")

	DMain:SetPos(ScrW(),ScrH())
	DMain:SetSize(800, 400)
	DMain:Center()
	DMain:SetTitle("")
	DMain:SetVisible(true)
	DMain:ShowCloseButton(false)
	DMain:SetDraggable(false)
	DMain:MakePopup()
		function DMain:Paint( w,h )
		
			draw.RoundedBox( 0, 0, 0, w, h, Color( 44, 62, 80, 255))
			draw.RoundedBox( 0, 0, 0, w, h-370, Color( 192, 57, 43, 255))
			draw.SimpleText( "Box System", "Bebas Neue", DMain:GetWide()-460, DMain:GetTall()-405, Color(255, 255, 255, 255))
			
	end
	
    closeButton = vgui.Create('DButton', DMain)
	closeButton:SetFont('Bebas Neue')
	closeButton:SetText('X')
	closeButton:SetColor(Color(255, 255, 255))
	closeButton:SetSize(50,50)
	closeButton:SetDrawBackground(false)
	closeButton:SetPos( DMain:GetWide()-40, DMain:GetTall()-407 )
	closeButton.DoClick = function()
		DMain:Remove()
	end 
end
MyMenu()

hook.Add( "Think", "GetKeyPress", function()
    if input.IsKeyDown(KEY_F6) then
        MyMenu()
    end
end)

surface.CreateFont( "Bebas Neue", {
	font = "Bebas Neue",
	size = 45,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )

Is this the whole file?

Yep, that’s the whole file.

Just an FYI, the surface.CreateFont should go above the function, not below.

Thanks for the tip, i’ll fix that.

Lel you little Cheeky Dug. I can help you with some of this if you want?

Get on steam then you lil dug.

Why are you attempting to use DMain before its being created?

Take out:
[lua]
if IsValid(DMain) then DMain:Remove() end
if IsValid(closeButton) then closeButton:Remove() end
[/lua]

Instead of taking them out, can I place them lower in the file?

Why would you want to remove them, this would check if they are valid which would return true… then it would immediately remove them closing them out of the screen…

Well, with your version that you posted, you’ll open up the derma menu and try to exit it, it’ll stay on your screen and spam your console with this error

[ERROR] lua/autorun/client/derma.lua:35: Tried to use invalid object (type Panel) (Object was NULL or not of the right type)

  1. GetWide - [C]:-1
  2. unknown - lua/autorun/client/derma.lua:35

-SNIP-

Fixed it in the post below ^.^

Still receiving the error…

I got you bro.

[lua]
if (CLIENT) then
surface.CreateFont( “Bebas Neue”, {font = “Bebas Neue”,
size = 45,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
} )
end

function Hnaknaw()

	pnlMain = vgui.Create( "DFrame" )
pnlMain:SetTitle('')
pnlMain:ShowCloseButton(false)
pnlMain:SetSize( 800, 400 )
pnlMain:Center()
pnlMain:MakePopup()
pnlMain.Paint = function(self, w, h)
		draw.RoundedBox( 0, 0, 0, w, h, Color( 44, 62, 80, 255))
		draw.RoundedBox( 0, 0, 0, w, h-370, Color( 192, 57, 43, 255))
		draw.SimpleText( "Box System", "Bebas Neue", pnlMain:GetWide() - 460, pnlMain:GetTall() - 405, Color(255, 255, 255, 255))
end

local btnClose = vgui.Create(‘DButton’, pnlMain)
btnClose:SetParent(pnlMain)
btnClose:SetPos( pnlMain:GetWide()-40, pnlMain:GetTall()-407 )
btnClose:SetSize(50,50)
btnClose:SetFont(‘Bebas Neue’)
btnClose:SetText(‘X’)
btnClose:SetColor(Color(255, 255, 255))
btnClose:SetDrawBackground(false)
btnClose.DoClick = function()
pnlMain:Remove()
end

pnlMain:MakePopup()

end

function NipsToNis()
if input.IsKeyDown(KEY_F6) then
if HKDown then return end

	HKDown = true
	if IsValid(pnlMain) then
		pnlMain:SetVisible(not pnlMain:IsVisible())
	else
		Hnaknaw()
	end
else
	HKDown = false
end

end

hook.Add(“Think”, “GetKeyPress”, NipsToNis)
[/lua]

Thanks alot man, I also love the names of the functions :wink: