• Adding hooks and not breaking VGUI?
    2 replies, posted
I'm pretty new to gmod lua scripting so I'm trying to figure out why my code is getting this error: [ERROR] lua/randommodnamehere/menu.lua:4: attempt to index global 'vgui' (a nil value)   1. MenuCreateUI - lua/modnamehere/menu.lua:4    2. unknown - lua/init.lua:13 I have a init.lua file -- Files to be downloaded to clients AddCSLuaFile("randommodnamehere/menu.lua") -- Included files include("randommodnamehere/menu.lua") -- Setup commands concommand.Add("gd_menu_toggle", function() MenuToggleUI() end, nil, "Used for enabling the GDevices menu", FCVAR_CLIENTCMD_CAN_EXECUTE) -- Initializers MenuCreateUI() -- Below is causing the issue... hook.Add("PlayerSay", "ChatCommandListener", function(ply, text, team)  if(text == "!gd") then MenuToggleUI() end end) and a menu.lua file local menu function MenuCreateUI() menu = vgui.Create("DFrame") menu:SetVisible(false) menu:SetSize(1240, 720) menu:Center() menu:SetTitle("Gmod Devices Menu") menu:SetTooltip("Mod menu for spawing GDevices props.") menu:SetSizable(false) menu:SetDeleteOnClose(false)     -- frame.MakePopup()     end function MenuToggleUI() menu:SetVisible(!menu:IsVisible()) end Without the hook running the script from the client runs fine. With the hook I can't run the file from the client using: lua_openscript_cl init.lua or lua_openscript init.lua I want to throw out there I've only learned how to make scripts from the documentation on the Wiki so far. Does anyone know what stupid mistake I made? Or do I just not get something?
PlayerSay is serverside. Use OnPlayerChat.
I'd also suggest separating your realm-specific (serverside, clientside) code more. Out of the code you pasted, the only thing the server needs to run is AddCSLuaFile. The rest should be purely in the client's realm. Like it is now, the server is creating unnecessary hooks and functions that it can't even run.
Sorry, you need to Log In to post a reply to this thread.