Serializing a Variable, but still getting an error saying the variable isn't assigned.

So I am currently working on making a game, and im trying to get the raycasting to work. I have a private field, witch has been serialized, made to set up the camera from which the ray will be cast. Every time I try to shoot however, it pops up an error:

NullReferenceException: Object reference not set to an instance of an object
playerShoot.shoot () (at Assets/Scripts/playerShoot.cs:33)
playerShoot.Update () (at Assets/Scripts/playerShoot.cs:24)

I have tried making the variables public, but the error is still there. Here is the code as well:

using UnityEngine;
using UnityEngine.Networking;

public class playerShoot : NetworkBehaviour {

    public playerWeapon weapon;

    [SerializeField]
    private Camera cam;

    [SerializeField]
    private LayerMask mask;

    void Start()
    {
        if (cam == null)
        {
            Debug.LogError("No camera Assigned");
            enabled = false;
        }
    }

    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            shoot();
        }

    }
  
    [Client]
    void shoot()
    {
        RaycastHit _hit;
        if(Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, weapon.range, mask))
        {
            if (_hit.collider.tag == "Player")
            {
                CmdPlayerShot(_hit.collider.name);
            }
        }
    }

    [Command]
    void CmdPlayerShot(string _ID)
    {
        Debug.Log(_ID + "has been shot");
    }
}

If anyone can help me figure out how to make it so that i can assign my variables in the inspector like im doing now, preferably without the variables being public, then that would be amazing.
Note that I have tried to ignore the warnings but that does not work.
Note 2: The error lines are a little off as I had edited it after the error to get the original code, but the error is still the same one.

what’s nullreffing? The cam or the weapon?

Your Start’s disabling the script, so I’m guessing it’s the weapon.range line that’s the problem.

You’re not testing to see if you actually hit anything…if _hit.collider is null, which it will be if you don’t hit anything, then you’ll get a null reference while trying to get that null collider’s tag.

This has nothing to do with serialization or the editor, the error log points you to the exact line where the null reference occurs (although you stripped that error line out of the stack you gave us for some reason). I recommend you go back to the basics and start learning about the language from the ground up until you have a better understanding of what’s going on here and how you should have debugged it.

he’s totally wrapped that raycast in an if-statement, so… no?

Whoops, spaced that.
I think I get the picture…We need to see your PlayerWeapon class.