Issues with Derma

Hello, I’m unsure as to what I’m doing wrong, I’m doing a simple derma test, I get the error message
dermatest.lua:3: attempt to index global ‘vgui’ (a nil value) every time I attempt to bring the derma panel up.
I looked up a solution and people said you have to include it in cl_init.lua, and init.lua. I’ve included it correctly in the sandbox gamemode, and still same error. Am I including it in the wrong place? I just figured I’d need to include it in the sandbox gamemode’s cl_init since that’s the gamemode I’m testing on. If somebody could tell me what I’m doing wrong, it would be much appreciated. Thanks!

[editline]08:21PM[/editline]

[lua]

function testframe()
local frame1 = vgui.Create( “DFrame” )

    frame1:SetPos(100,100)
    frame1:SetSize(200,200)
    frame1:SetTitle("Test")
    frame1:MakePopup()

end
concommand.Add(“testframe”, testframe)
[/lua]

I wouldnt put it in sandbox, put the function in its own Lua file, place the Lua file in garrysmod/lua and open a singleplayer game.

In console type “lua_openscript_cl FILENAME.lua”

This will run your script, and most likely fix your issue.

I don’t have the function inside the sandbox gamemode, I just have it included, like include( ‘cl_dermatest.lua’ ) so it’s in it’s own file already. And having it in /lua folder didn’t help. That’s where I had it at first.

Well you definitely dont need to include it in the sandbox gamemode, just look at the structure of an entity off of garrysmod.org and put your file in addon format.

Putting the file in the /lua folder actually helps a lot, because you can reload your script without restarting the gamemode, which saves a lot of time with things like Derma where you have to make a lot of very small changes.

Don’t include it in init.lua. The vgui library doesn’t exist on the server, which is where your nil value errors are coming from. Check the colour of errors you get though - blue means server, yellow means client.

It’s blue, so how do I get the vgui library to exist on the server?

You don’t. Place the file in garrysmod/autorun/client and it will be executed on the client.