How to add derma to a SWEP?

Hey everyone, I’m having a bit of trouble getting a derma menu to work in the SWEP:SecondaryAttack part of a weapon. For some reason it works on a server but not on singleplayer. I have tried different ways in an attempt to solve the problem but keep ending up unsuccessful. I’m not sure whether it actually works at all on singplayer or what exactly it will take for me to have it work so basically I just want to know what it will require for me to get a derma menu to work in the SecondaryAttack part of a SWEP. All I’m looking for is for someone to lead me in the right direction by letting me know if this can be done or not and or letting me know if it needs to be in a certain place or defined somewhere. If you need anymore information about what I’m trying to do just let me know. Thanks in advance!

Pretty vague question… What exactly is the problem? The menu doesn’t open up in singleplayer? Or what?

Yeah, it doesn’t in singleplayer but does in multiplayer. I managed to produce an error to find out why it wasn’t working in singleplayer and it said something along the lines of ‘attempted to index a global DermaMenu’.

I’m no expert, but i think its a problem with the global thing, maybe you can set it to be something else? A question tho, why do you mind if it works in multiplayer?

I’d tell you to post the code here if you want serious answers. I can’t really help much but others may if they see the code obviously

I want the code to work both in singleplayer AND multiplayer. And I know it’s a problem related to the error but I’m trying to find out what exactly. I’ve already tried it as a clientside code and a serverside code but neither make any positive changes so yeah… Anyways, here’s the main part of the code I’m working on (the code below is just a simple test code, not what I’m actually planning on doing although it uses the same sort of concept…):

function SWEP:SecondaryAttack()
local menu = DermaMenu()
menu:AddOption( "TestOption1", function() print("You clicked TestOption1!") end )
menu:AddOption( "TestOption2", function() print("You clicked TestOption2!") end )

Gotta add those panels! And Positions!

just add normal derma inside the cl_init?

What do you mean? I want this in SWEP:SecondaryAttack which isn’t a client side function.

Use user messages or something.

Thank you so much! It worked!