null variable error, but it is assigned in the code

I’m making a multiplayer game in unity using Netcode for Gameobjects. I allowed each player to have their own camera that follows them. The system worked fine.

However, when I disabled it to do some debugging for something else, and then reenabled it, suddenly I get an error, because the camera holder variable isn’t assigned:
“NullReferenceException: Object reference not set to an instance of an object
CamController.Start () (at Assets/Scripts/CamController.cs:19)”
and
“NullReferenceException: Object reference not set to an instance of an object
CamController.FixedUpdate () (at Assets/Scripts/CamController.cs:31)”

The thing is, I want that variable to be assigned in the code, when the player instantiates their own camera holder. I can’t set it to private, because I need another script to access it, and I can’t make it local, because multiple functions need it.

Here are the scripts (they’re both assigned to the player):

using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;

public class Player : NetworkBehaviour
{
    private Rigidbody playerRb;
    public GameObject camHolderPrfb;
    public GameObject camHolder;
    public float speed;
    public float jumpForce;
    public float gravityMod;
    private bool onGround = true;

    void Start()
    {
        camHolder = Instantiate(camHolderPrfb, transform.position, Quaternion.identity);
        playerRb = GetComponent<Rigidbody>();
        Physics.gravity *= gravityMod;
    }

    void Update()
    {
        //Makes sure player can only control its character
        if (!IsOwner) {enabled = false;} 
        //Calculates player movement
        float forwInput = Input.GetAxis("Vertical");
        float horzInput = Input.GetAxis("Horizontal");
        Vector3 direction = camHolder.transform.forward * forwInput + camHolder.transform.right * horzInput;
        //Applies movement to player
        if (direction.magnitude > 1) {direction.Normalize();}
        playerRb.AddForce(direction * speed);
        
        //Allows player to jump
        if(Input.GetKeyDown(KeyCode.Space) && onGround) {
            onGround = false;
            playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        }
    }
    
    //Ensures player can only jump if it's touching the ground
    void OnCollisionEnter(Collision collision) 
    {
        if (collision.gameObject.CompareTag("Ground")) {
            onGround = true;
        }
    }
}

Second:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Unity.Netcode;

public class CamController : NetworkBehaviour
{

    public float rotationSpeed;
    public float lerpSpeed;
    public GameObject camHolder;
    private Camera playerCamComp;
    private GameObject playerCam;
    public Player PlayerScr;

    void Start() 
    {
        camHolder = PlayerScr.camHolder;
        playerCamComp = camHolder.GetComponentInChildren<Camera>();
        playerCam = playerCamComp.gameObject;
    }

    void FixedUpdate()
    {
        //Camera is rotatable with left and right keys
        float camInput = Input.GetAxis("MoveCam");
        camHolder.transform.Rotate(Vector3.up, camInput * Time.deltaTime * rotationSpeed);
        //Camera moves and looks at the player
        camHolder.transform.position = Vector3.Lerp(camHolder.transform.position, transform.position, lerpSpeed * Time.deltaTime);
        playerCam.transform.LookAt(this.transform);
    }
}

Aside from what I mentioned earlier, I also tried initially assigning some other random prefab that I created for this purpose, but it didn’t work.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật