Is there a way to run Destroy(gameObject) after the game has run the previous code?

Is there a way I can run the Destroy(gameObject) after the game has run everything before it? because I always get errors or PlaySound(0); doesn’t actually play because the gameObject is destroyed instantly and if I use Destroy(gameObject, 1) it takes too long to destroy it :confused:

if ( == "BlueWall")
                ScoreSystem scoreSystem = GetComponent<ScoreSystem>();

Use an IEnumerator to wait in a while loop for whatever you want to finish

 public class DestroyStuff{

 public bool hasFinished;
 public GameObject desObj;

 IEnumerator DestroySounds (){
       while (!hasFinished){
              yield return null;