DMenu not working properly?

So, I am not sure if I am doing it wrong, or it is broken or whatever, but I am trying to create a DMenu.

I am making a simple entity, which upon pressing USE on, will open a menu with weapons, weapon models, info etc. So far everything worked as I expected, weapons get added, clicking on them shows the info, double clicking gives you the weapon. For every weapon icon, I added a Menu, which upon right clicking the Icon should open the menu. But instead, it gives me the error: attempt to call method ‘Open’ (a nil value) . I tried different functions, like IconMenu:SetVisible(), which provided me with another error: Tried to use invalid object (type Panel) (Object was NULL or not of the right type). So, if anyone knows what can be the problem, please let me know. I honestly dont know what can be wrong.

This is how the menu looks so far (just basic stuff):

This is the code for the icon and menu part

local icon = vgui.Create( “DModelPanel”, BG )
icon:SetSize( BG:GetSize(), BG:GetSize())

	local IconMenu = vgui.Create( "DMenu", BG )
	IconMenu:AddOption("Test Option")
	icon.DoRightClick = function()


DMenu isn’t a vgui element, it’s a function.

It is a vgui element. DermaMenu is the one that is a function.

Do not parent the DMenu, it cannot be parented to “BG”.

I tried not parenting it to anything, it still kept erroring

Dud you try doing “local IconMenu = DermaMenu()”?

Yup. I tried like everything I could have, I even copied the DMenu example from the wiki page, and it did not work either. Realy weird

icon.DoRightClick = function()
	local IconMenu = DermaMenu()
	IconMenu:AddOption("Test Option")

Hmm I will check that that tomorow, but looks like its something

DModelPanel does not have DoRightClick hook/callback.

Use one of these:

Just a tip- those work for all panels (I think)

Yeah, they kinda work on anything.

[editline]28th September 2016[/editline]

Thank you very much, that did the trick. Works as I wanted