Audiolistener not disabling in build

I have a pause menu when ESC is pressed.

if(Input.GetButtonDown("PauseMenu"))
{
	
	
	if(pauseMenuOn)
	{
		Time.timeScale = 1.0;
		Screen.showCursor = false;
		Camera.main.GetComponent("AudioListener").enabled = true;
		pauseMenuOn = false;
		sceneManager.SendMessage("ResetMenu");
	}
	
	else
	{
		
		Time.timeScale = 0;
		Screen.showCursor = true;
		Camera.main.GetComponent("AudioListener").enabled = false;
		pauseMenuOn = true;
	}
}

My aim is to disable all sounds when this button is pressed. It works just fine when I run the game in editor. But when I build the game and run the exe file, when ESC is pressed while in game sounds keep playing. I am very confused why this happens.

Any help would be appereciated. Thanks.

Ok I solved the issue I made 2 functions in GameManager, EnableSound and DisableSound and called them instead of disablig the audiolistener.

function DisableSound()
{
     Camera.main.GetComponent("AudioListener").volume = 0;
}
function EnableSound()
{
     Camera.main.GetComponent("AudioListener").volume = PlayerPrefs.GetFloat("Sound Volume");
}