calling field "send" is a nill value?

so I have this swep which works perfectly fine on SP but not on servers or on 2 player?

function SWEP:PrimaryAttack() 

	fsttimeclicked = not fsttimeclicked
	net.Send(self:GetOwner()) // this is the line


I get this error and I cant figure out why (code doesnt work too in multiplayer)

[ERROR] addons/rockford_swep/lua/weapons/rockford_map/shared.lua:25: attempt to call field 'Send' (a nil value)
  1. unknown - addons/rockford_swep/lua/weapons/rockford_map/shared.lua:25

please help i am lost

net.Send is a serverside function and you’re calling it in a shared function.

Your PrimaryAttack function should still be shared, but you should use a SERVER check to make your net code only run serverside. Also, use a class variable instead of global/local for fsttimeclicked

function SWEP:PrimaryAttack() 
   if SERVER then 
	fsttimeclicked = not fsttimeclicked


This didnt fix it tough? And I cant put a shared function inside init ?

Are you getting the same error? Perhaps that function (minus the if SERVER part) has been copied in cl_init.lua.

I am not getting any error now, but it doesnt work.
I recieve the net message in cl_init thats all

That’s what your code is supposed to do right?

If there’s something else broken as well show us that part.

What do you mean it doesn’t work? Have you tried adding print checks to see if the message is actually being sent and if it’s actually being received? Can you show the whole code?

img snipped

i dont really think anything is wrong in there, it only fails at shared.lua’s part

img snipped

Can you post your init code?

everything seems right to me :l

Can you actually describe what happens when you try clicking? Have you added print checks to see if:

  1. the net message is actually being sent by the server
  2. fsttimeclicked is true or false
  3. the net message is actually being received by the client
  4. the received boolean is what you expect

For now you’re being incredibly vague almost like you expect us to test and fix the code for you. We can’t help you if you don’t put the effort of trying things yourself and seeing what may be wrong.
With the print checks I mentioned above you can see at which point your script doesn’t work, and from there you can try stuff to fix your issue.

Also, fsttimeclicked is going to conflict between weapon instances unless you make it a class variable.

No honestly not,
I talked to code_gs on discord and told him what the swep is supposed to do on CLICKing it,
basically on primary attack it opens a derma, and pressing it again removes it
I dont expect anyone to test or fix the code I just want to know where I made my mistakes and why it was one

[editline]21st October 2017[/editline]

Still dont quite grasp how to put it as a class variable

self:GetOwner().fsttimeclicked or SWEP.fsttimeclicked?

Don’t network a bool at all - just tell the client to toggle the image state.

How do I do that tho?
I cant send nothing I suppose so a bool is literally the next best thing for me

Send no content. Just the net message.

net.Receive it at the client and toggle the menu

Just receiving the message is enough. Needs to be no content.


oh! thanks, you guys helped me a bunch and I think I got it to work correctly now/