What am I doing wrong?

I was following this video but when I hit start the object just destroys itself. What am I doing wrong?

Heres my script:

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

public class Music : MonoBehaviour
{
     void Awake()
    {
        GameObject[] objs = GameObject.FindGameObjectsWithTag("Music");
        if (objs.Length > 1)
            Destroy(this.gameObject);
        DontDestroyOnLoad(this.gameObject);
    }
}

I’m guessing your starting scene has more than one object with the “Music” tag. This script doesn’t handle that case properly. Make sure your starting scene only has a single “Music” tagged object.

1 Like

Thank you this was the problem. It works now!