VGUI code isnt working

So im trying to make a VGUI on a swep to open when left click but nothing will happend when i left click. Help thanks
and yes i have looked at tutorials and videos but still wont work i cant figure it out there are no script errors when i left click

Code:



function SWEP:window()
	if CLIENT then
	local Form = vgui.Create( "DFrame" )
	Form:SetPos( 200, 200 ) -- Position form on your monitor
	Form:SetSize( 300, 150 ) -- Size form
	Form:SetTitle( "Name window" ) -- Form set name
	Form:SetVisible( true ) -- Form rendered ( true or false )
	Form:SetDraggable( false ) -- Form draggable
	Form:ShowCloseButton( true ) -- Show buttons panel
	Form:MakePopup()
	chat.AddText(Color(255,0,0), "test" )
end
end

function SWEP:PrimaryAttack()
	self:window()
end


As far as I remember, PrimaryAttack is a shared function, but never gets called clientside. Try making a net messageto the SWEP owner, and then linking the window function to that message.

can you help me with the net message? im confused

You can adapt what I wrote here to your needs, or use the one on the wiki

many thanks

Send the message from the server.

Add
[lua]util.AddNetworkString(“vguishow”)[/lua]
to the beginning of your init file on the SWEP.

Add
[lua]net.Start(“vguishow”)
net.Send(self.Owner)[/lua]
to the PrimaryAttack function.

Change the window to
[lua]function window()
local Form = vgui.Create( “DFrame” )
Form:SetPos( 200, 200 ) – Position form on your monitor
Form:SetSize( 300, 150 ) – Size form
Form:SetTitle( “Name window” ) – Form set name
Form:SetVisible( true ) – Form rendered ( true or false )
Form:SetDraggable( false ) – Form draggable
Form:ShowCloseButton( true ) – Show buttons panel
Form:MakePopup()
chat.AddText(Color(255,0,0), “test” )
end
net.Receive( “vguishow”, window)[/lua]

still not working now with an error! :frowning:



function window()
	if CLIENT then
	local Form = vgui.Create( "DFrame" )
	Form:SetPos( 200, 200 ) -- Position form on your monitor
	Form:SetSize( 300, 150 ) -- Size form
	Form:SetTitle( "Name window" ) -- Form set name
	Form:SetVisible( true ) -- Form rendered ( true or false )
	Form:SetDraggable( false ) -- Form draggable
	Form:ShowCloseButton( true ) -- Show buttons panel
	Form:MakePopup()
	chat.AddText(Color(255,0,0), "test" )
end
end

net.Receive( "vguishow", window)

function SWEP:PrimaryAttack( ply )
	window()
	net.Start("vguishow")
	net.Send(self.Owner)
end


here is the cl_init file code:



AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");
include("shared.lua");

util.AddNetworkString("vguishow")

SWEP.Weight=5;
SWEP.AutoSwitchTo=false;
SWEP.AutoSwitchFrom=false;


The error is




[ERROR] addons/swep_maker/lua/weapons/main_maker/shared.lua:55: Calling net.Start with unpooled message name [http://goo.gl/qcx0y]
  1. Start - [C]:-1
   2. unknown - addons/swep_maker/lua/weapons/main_maker/shared.lua:55


directory of cl_init is:
lua\weapons\main_maker\cl_init.lua

addNetworkString has to be in the init file, not the cl_init. It’s a serverside function.

Thanks for your paitence :slight_smile: i got it all working now :smiley: