How to make a line of code run once in C#?

Alright, so I’m currently developing a 3D platformer game, and I am working on an options bug. This bug being that I can turn a bool to false, and then I go into a level, go back into the same menu Scene, and the music starts playing even though I turned it off before. I am using a toggle to turn on and off the bool.

Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Options : MonoBehaviour
{
    public static bool isMusic;
    public static bool isCoinSFX;
    void Start()
    {
        isMusic = true;
        isCoinSFX = true;
    }

    void Update()
    {

    }

    public void MusicValueChange()
    {
        isMusic = !isMusic;
    }

    public void CoinSFXChange()
    {
        isCoinSFX = !isCoinSFX;
    }
}

Yes, I know I have to remove the code in the Start, but then the Toggle will be inverted. (When it’s toggled off, the music is on and vise versa) Please help if you see this and know the answer.

  1. Remove the callbacks you’ve set on the Toggles from the inspector

  2. Remove the Options component from the hierarchy

  3. Replace the code of the Options class by the one below

  4. Create a new script called OptionToggles and add it to the hierarchy (see script below)

  5. Drag & drop the toggles in the inspector of the OptionToggles component

    public static class Options
    {
    public static bool isMusic;
    public static bool isCoinSFX;
    }

    using UnityEngine;
    using UnityEngine.UI;

    public class OptionToggles : MonoBehaviour
    {
    public Toggle musicToggle; // Drag & drop in inspector
    public Toggle coinsSFXToggle; // Drag & drop in inspector

    private void Start()
    {
        musicToggle.isOn = Options.isMusic;
        coinsSFXToggle.isOn = Options.isCoinSFX;
    
        musicToggle.onValueChanged.addListener(value => Options.isMusic = value);
        coinsSFXToggle.onValueChanged.addListener(value => Options.isCoinSFX = value);
    }
    

    }

Ok, so I did what you had suggested and I don’t see anything changed. The music is still playing after I go back into the scene. What code do you need to see? The code for my music is the following:

// this is Music.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Music : MonoBehaviour
{
    public AudioSource BackgroundMusic;
    void Start()
    {
        BackgroundMusic.UnPause();
    }

    void Update()
    {
        if (Options.isMusic)
        {
            BackgroundMusic.UnPause();
        }
        else
        {
            BackgroundMusic.Pause();
        }
    }
}

If you need to see any other code then ask. Thank you for helping.