VGUI Problem

I’m trying to use Derma to make a very simple menu, but when I try to open a panel using the code


	local plantwinow = vgui.Create("DFrame")
	plantwinow:SetSize(202, 102)
	plantwinow:Center()
	plantwinow:SetTitle("Level " +lvltext +" Plant")
	plantwinow:SetDraggable(true)
	plantwinow:SetSizable(false)
	plantwinow:ShowCloseButton(true)
	plantwinow:MakePopup()

but when I run it Gmod says


attempt to index global 'vgui' (a nil value)

Does anyone know how to fix this?

Don’t run it on the server.

I’m currently running it as part of cl_init.lua. It’s part of a SENT I’m making.

You are wrong, vgui is always available on the client, check your code.

The only reason why vgui is nil that you either overwrote it run the code on the server.

Nope. Even outside of the SENT, I tried putting


lua_run local plantwindow = vgui.Create(DFrame)

into the Gmod command console during a singleplayer game and it still returned


[lua_run:1] attempt to index global 'vgui' (a nil value)

so that doesn’t seem to work.

Once again you’re running it serverside.

lua_run_cl not lua_run

[lua]
local plantwinow = vgui.Create(“DFrame”)
plantwinow:SetSize(202, 102)
plantwinow:Center()
plantwinow:SetTitle(“Level " +lvltext +” Plant")
plantwinow:SetDraggable(true)
plantwinow:SetSizable(false)
plantwinow:ShowCloseButton(true)
plantwinow:MakePopup()

if (SERVER) then print(“Running on server!”) end
if (CLIENT) then print(“Running on client!”) e
[/lua]

Run that OP alongside your original code, and it’ll tell you whether or not it’s being run in the server too.

If it doesn’t show that it’s running on the server, and vgui still returns nil, make sure you haven’t got any other addons fucking it up.

I looked into it using the


if (SERVER) then print("Running on server!") end
if (CLIENT) then print("Running on client!") end

method and it turned out that an addon was messing it up. Thanks to everyone for helping me figure out what it was!