Can't call script from another scene using DONTDESTROYONLOAD().

I wanna alter the variable of senstivityX and sensitvityY of player. MouseController script is attached to the player and camera of the player.
The player is in another scene.
I wanna change the mouse sensitivity from the Main Menu Scene using Slider.
I’m using DontDestroyOnLoad() function to accomplish this. But, the problem is show me the error

Object not set to an reference.

Actually, the MENU script (it’s in MainMenu scene) tries to search the player within Main Menu scene, whereas player in another scene(“FPS_Battle”).
I don’t know what am I doing wrong. Even though I’m using the DontDestroyOnLoad() function.

Here’s menu script which is assigned to an empty gameobject and it’s in Main Menu scene.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Menu : MonoBehaviour {
	
	private Slider sens;
	private GameObject playerSens;
	private GameObject CameraSens;
	void Start(){
		DontDestroyOnLoad (this.gameObject); //dont destroy this gameobject so that it can be used further in another scene.
		sens = GameObject.FindGameObjectWithTag ("sensX").GetComponent<Slider> (); //access the slider compoenent in scene1(menu);
		playerSens = GameObject.FindGameObjectWithTag ("Player"); //search for the player gameobect of player in scene2 
		CameraSens = GameObject.FindGameObjectWithTag ("CameraSens"); //search for the camera gameobject of player in scene2
		
	}
	public void Senstivity(){
		playerSens.GetComponent<MouseController> ().sensitivityX = sens.value; //change the sensitivity of player - X axis - **
			CameraSens.GetComponent<MouseController> ().sensitivityY = sens.value; //change the senstivity of camera - Y axis
	}
 //When I change the senstivity it shows from error that object not reference set. **

	}

}

I don’t wanna use STATIC keyword as it poses some problems for me.
Thanks!!

Hi bud,

Gonna need one little detail if you don’t mind.

Is DontDestroyOnLoad() working as intended. Also, which part of script is giving the error.

If DontDestroyOnLoad() is not working, please let me know.

At the time of Start() for the Menu no objects in scene2 exists, causing GameObject.FindGameObjectWithTag to fail.

I use a singleton DoNotDestroy GameManager class to handle scene transitions and passing variables between scenes. I also think you will have to use static variables.

@AshwinTheGammer
Since the player doesnt exist in start of Menu.cs ( as player is in scene2), you cannot find player with tag in the Start() of Menu.cs. Here is a workaroud.
Take a public variable in Menu.cs

  public float sensitivity;
  public void Senstivity(){
     sensitivity = sens.value;
 } 

In your next scene, where you can find player, use the following line in Start() of either MouseController.cs or some other script that can access MouseController.cs in Scene2

  float sensitivity = FindObjectOfType<Menu>(). sensitivity;
  sensitivityX = sensitivity;
  sensitivityY = sensitivity;

As you have written DontDestroyOnLoad() in Menu.cs, this script would be available in scene 2 in the start of MouseController.cs and the above snippet would work.