What's wrong with my menu :(

It’s probably going to end up as something obvious that i don’t notice

[lua]function Menutest()

local ply = LocalPlayer()
local AButton = vgui.Create( "DButton", BackGround )
local BackGround = vgui.Create( "DFrame" )

BackGround:SetSize( 200, 90 )
BackGround:SetPos( (ScrW()/2)-BackGround:GetWide(), (ScrH()/2)-BackGround:GetTall() )
BackGround:SetTitle( "Ninjas - Main Menu" )
BackGround:SetVisible( true )
BackGround:SetDraggable( true )
BackGround:ShowCloseButton( true )
BackGround:MakePopup()


AButton:SetSize( 160, 40 )
AButton:SetText( "Ninja Heal" )
AButton:SetPos( 20, 30 )
AButton:DoClick = function()
	ply:ConCommand( "say HEALLLL!!!!!!!" )
end

end

concommand.Add( “openmenu”, Menutest )[/lua]

And whats wrong? Any errors?

well when im in console and i type “openmenu” the menu doesn’t come up

(sorry for not clarifying the problem)

You didn’t create the GUI.

-snip-

whaddayu mean

You are defining AButton and setting it’s parent to BackGround before defining BackGround.

Basically change this
[lua] local ply = LocalPlayer()
local AButton = vgui.Create( “DButton”, BackGround )
local BackGround = vgui.Create( “DFrame” )[/lua]

To this

[lua] local ply = LocalPlayer()
local BackGround = vgui.Create( “DFrame” )
local AButton = vgui.Create( “DButton”, BackGround )[/lua]

That isn’t going to stop it from opening though, the button will just be behind the menu and in the wrong place. When you type ‘openmenu’ in the console, does it say “unknown command: openmenu”?

yes it says exactly that

[lua]function Menutest()[/lua]
Needs to be
[lua]function Menutest(pl, cmd, args)[/lua]

Wait no nevermind. That’s always the problem for me, but it still didn’t work when I tested it.

[editline]11:29PM[/editline]

Oh it’s that you’re trying to parent AButton to BackGround before BackGround exists.
Just move line 4 somewhere below line 5

[editline]11:30PM[/editline]

Also
[lua]AButton:DoClick = function()[/lua]
should be
[lua]AButton:DoClick = function(AButton)[/lua]

[editline]11:33PM[/editline]

[lua]function Menutest(pl, cmd, args) – ConCommands need 3 arguments

local ply = LocalPlayer()
local BackGround = vgui.Create( "DFrame" )

BackGround:SetSize( 200, 90 )
BackGround:SetPos( (ScrW()/2)-BackGround:GetWide(), (ScrH()/2)-BackGround:GetTall() )
BackGround:SetTitle( "Ninjas - Main Menu" )
BackGround:SetVisible( true )
BackGround:SetDraggable( true )
BackGround:ShowCloseButton( true )
BackGround:MakePopup()

local AButton = vgui.Create( "DButton", BackGround ) -- If you add BackGround after the "DButton" you are parenting the button to BackGround, so BackGround needs to exist first
AButton:SetSize( 160, 40 )
AButton:SetText( "Ninja Heal" )
AButton:SetPos( 20, 30 )
AButton:DoClick = function(AButton) -- You need to have AButton as an argument to this function
	ply:ConCommand( "say HEALLLL!!!!!!!" )
end

end

concommand.Add( “openmenu”, Menutest )[/lua]

That’s the full thing.

[editline]11:39PM[/editline]

It still doesn’t work for me. Hmm…

Uh, are you sure that you opened the code? Or did it run in the gamemode you made? If you get unknown command, that means the command wasn’t even made.

well I’m in the gamemode ninjas, i have the file placed in lua/autorun/client in the ninjas gamemode and in the garrys mod folder (this is run off a server)

[editline]08:28PM[/editline]

Could it be the custom HUD i was working on
(it’s very basic right now)
[lua]include( ‘shared.lua’ )

function hidehud( name )
for k, v in pairs{ “CHudHealth”, “CHudBattery” } do
if name == v then return false end
end
end

hook.Add( “HUDShouldDraw”, “hidehud”, hidehud )

function GM:HUDPaint()

local player = LocalPlayer()

local Health = LocalPlayer():Health()

surface.CreateFont( "coolvetica", 124, 400, false, false, "ninja" )

surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos(34, (ScrH()/2)+(ScrH()/4) )
surface.SetFont( "ninja" )
surface.DrawText( Health )
GAMEMODE:DrawDeathNotice( 0.85, 0.04 )

end
[/lua]
maybe that’s interfering with the menu showing up because originally it didnt even show death events which is why i added this [lua]GAMEMODE:DrawDeathNotice( 0.85, 0.04 )[/lua]

I don’t think it is to do with that, I think you need to put the file in gamemode/menu.lua and include and AddCSLuaFile it (include it in cl_init.lua and AddCSLuaFile it in init.lua)

ok in init.lua i did
[lua]AddCSLuaFile( “menu.lua” )[/lua]
and in cl_init.lia i did
[lua]include( “menu.lua” )[/lua]
the file is in gamemode/menu.lua (where the init and clinit are)
upon me running the server i get this in console

Couldn’t include file ‘menu.lua’ (File not found)

[editline]02:19PM[/editline]

ok problem fixed, i used Jo The Shmo’s fix
and updating the server cache made everything work

thanks everyone who helped

[editline]02:20PM[/editline]

oh yes and MakeR’s
includes and adds
thanks dude