Errors when trying to pause audio with game ()

I’ve been working on a script that pauses the game. I wanted the music to pause with the game, So I added a reference to the camera’s AudioSource in the script, and set it to pause and unpause with the game. However, when trying to test the game afterwards, it spits out this error:

NullReferenceException: Object reference not set to an instance of an object
PauseScript.Update () (at Assets/Scripts/PauseScript.cs:28)

I went back and checked the script, but I can’t figure out what the issue is. There is a warning that the camera reference is never used, but it looks used to me. Any help?

BTW Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseScript : MonoBehaviour { 

	public bool paused;

	private Camera cam;

	// Use this for initialization
	void Start () {
		paused = false;
	// Update is called once per frame
	void Update () {

		if (Input.GetButtonDown ("Select")) {
			paused = !paused;
			SoundManagerScript.PlaySound ("pause");
		if (paused) {
			Time.timeScale = 0;
		} else if (!paused) {
			Time.timeScale = 1;


Update: I’ve discovered the error, I forgot to add the reference in the Start function, it’s all good now!