Background Music Error!

Hi,

I am having trouble with my Background music. I assigned it to loop and not to delete on load but when you get back to the Main Menu it starts up again. I tried fixing it but I kept getting errors this is the code

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

public class NotDeleteMusic : MonoBehaviour {

	// Use this for initialization
	void Start () {
        // Identify your scene where you have to stop current running music and probably start new one
        if (SceneManager.sceneLoaded += "MainMenu")
        {
            // Find the game object who is playing the audio and STOP audio clip.
            GameObject.FindGameObjectWithTag("GameMusic").GetComponent<AudioSource>().Stop();
        }
        DontDestroyOnLoad(this);
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

You’re error is because your if statement is invalid.
SceneManager.sceneLoaded is an event you subscribe to, not a condition, replacing that for a proper event subscription should give you the desired results.

using UnityEngine;
using UnityEngine.SceneManagement;

public class NotDeleteMusic : MonoBehaviour
{
    void Start()
    {
        SceneManager.sceneLoaded += _SceneLoaded;
        DontDestroyOnLoad(this);
    }

    private void _SceneLoaded(Scene lScene, LoadSceneMode lMode)
    {
        if (lScene.name.Equals("MainMenu"))
        {
            GameObject.FindGameObjectWithTag("GameMusic").GetComponent<AudioSource>().Stop();
        }
    }
}