• Menu lua error
    9 replies, posted
Hello dear people of the community i am having issues fixing this problem, i am new to coding and don't know what the problem is this is the error i am getting when booting up the server [ERROR] gamemodes/basewars/gamemode/menu.lua:86: attempt to index global 'vgui' (a nil value)   1. unknown - gamemodes/basewars/gamemode/menu.lua:86    2. include - [C]:-1     3. unknown - gamemodes/basewars/gamemode/shared.lua:6      4. include - [C]:-1       5. unknown - gamemodes/basewars/gamemode/init.lua:9 [ERROR] gamemodes/basewars/gamemode/menu.lua:102: attempt to index global 'vgui' (a nil value)   1. unknown - gamemodes/basewars/gamemode/menu.lua:102    2. include - [C]:-1     3. unknown - gamemodes/basewars/gamemode/shared.lua:6      4. include - [C]:-1       5. unknown - gamemodes/basewars/gamemode/init.lua:9 and this is my code (shared.lua) GM.Name = "test" GM.Author = "Jenson" DeriveGamemode("sandbox") include("menu.lua") function GM:Initialize() end (menu.lua) local Menu net.Receive("FMenu", function() if (Menu == nil) then Menu = vgui.Create("DFrame") Menu:SetSize(750, 500) Menu:SetPos(ScrW() / 2 - 325, ScrH() / 2 - 250) Menu:SetTitle("Buy Menu") Menu:SetDraggable(false) Menu:ShowCloseButton(false) Menu:SetDeleteOnClose(false) Menu.Paint = function() surface.SetDrawColor(60,60,60,255) surface.DrawRect(0,0,Menu:GetWide(),Menu:GetTall()) surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,24,Menu:GetWide(),1) end end AddButtons(Menu) if(net.ReadBit() == 0) then Menu:Hide() gui.EnableScreenClicker(false) else Menu:Show() gui.EnableScreenClicker(true) end end) function AddButtons(Menu) local playerButton = vgui.Create("DButton") playerButton:SetParent(Menu) playerButton:SetText("") playerButton:SetSize(100,50) playerButton:SetPos(0, 25) playerButton.Paint = function() --color entire button surface.SetDrawColor(50,50,50,255) surface.DrawRect(0,0,playerButton:GetWide(),playerButton:GetTall()) -- draw bottom and right borders surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,49,playerButton:GetWide(),1) surface.DrawRect(99,0,1,playerButton:GetTall()) draw.DrawText("Info","DermaDefaultBold", playerButton:GetWide() / 2, 17, Color(255,255,255,255),1) end playerButton.DoClick = function(playerButton) local playerPanel = Menu:Add("PlayerPanel") end local shopButton = vgui.Create("DButton") shopButton:SetParent(Menu) shopButton:SetText("") shopButton:SetSize(100,50) shopButton:SetPos(0, 75) shopButton.Paint = function() --color entire button surface.SetDrawColor(50,50,50,255) surface.DrawRect(0,0,shopButton:GetWide(),shopButton:GetTall()) -- draw bottom and right borders surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,49,shopButton:GetWide(),1) surface.DrawRect(99,0,1,shopButton:GetTall()) draw.DrawText("Shop","DermaDefaultBold", shopButton:GetWide() / 2, 17, Color(255,255,255,255),1) end shopButton.DoClick = function(shopButton) local shopPanel = Menu:Add("ShopPanel") end end -- player panel PANEL = {} function PANEL:Init() -- initialize panel self:SetSize(650,475) self:SetPos(100,25) end function PANEL:Paint(w, h) draw.RoundedBox(0,0,0,w, h, Color(0,0,0,255)) end vgui.Register("PlayerPanel",PANEL,"Panel") -- end player panel -- player panel PANEL = {} function PANEL:Init() -- initialize panel self:SetSize(650,475) self:SetPos(100,25) end function PANEL:Paint(w, h) draw.RoundedBox(0,0,0,w, h, Color(255,255,255,255)) end vgui.Register("ShopPanel",PANEL,"Panel") -- end player panel and this is the init.lua AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") AddCSLuaFile("menu.lua") AddCSLuaFile("hud.lua") --AddCSLuaFile("workshop.lua") include("shared.lua") -- check if menu = open local open = false --menu show util.AddNetworkString("FMenu") function GM:ShowSpare2(ply) if (open == false) then open = true else open = false end net.Start("FMenu") net.WriteBit(open) net.Broadcast() end
vgui doesnt exist on server, its client-side only (you are including menu.lua on both)
Wait huh, i am only including it on shared.lua right? Do you mean the addcsluafile? Or well i dont understand :?
menu.lua to cl_menu.lua
Ill try this when i get acces to my pc, thanks for now!
Changing file prefixes does nothing by default.
But if i do that for some reason everyone gets it opened when 1 person clicks it on the server
That's because you're calling net.Broadcast in your init.lua - only send it to the player who pressed the button.
net.Start("FMenu") net.WriteBit(open) net.Send(ply) Also, is there any reason why you would do net.WriteBit instead of net.WriteBool?
wouldnt you want it to be local Menu = vgui.Create ( "Dframe" ) so ur not telling the server to do everything?
Sorry, you need to Log In to post a reply to this thread.