Unable to save UI elements after changing scene (MissingReferenceException)

Hello community

I’ve tried to work on UI for my project and everything works if I’m on the same scene.
However, if I change scene, my text-label for currency seems to dissapear and is not attached to a script as it initially was, due to the MissingReferenceException & my HP resets.

I’ve been trying to fiddle around with the following code and tried to only attach it to my EmptyObject that holds my UI, only the text and to my currency:

  public static DontDestroy instance = null;

    void Awake()
    {
        if (instance == null)
            instance = this; else Destroy(transform.gameObject); DontDestroyOnLoad(transform.gameObject);
    }

My approach has been that my FavorManager (which is the script for the currency, and holds the Text for display) always the script, just written for its proper class, and trying to put either the above script for each object seperately and simontaneously.
When I made my currency works as intended when changing scene, my HP would stop “tracking” and visa versa.

In the following link, it shows my Hierachy, my FavorManager, which hold the (pink) text and visual of my Screenshot by Lightshot.

I’m not sure what I should be looking for and hoped to get some guidance.

Kind regards
DaPham

Update:

I found out my issue, which was probably of a result of lack of sleep (from my side).

The above script is working as intended. The problem for me was where I was storing the data.
Sadly because of bad design, I chose to put the health variable on the player’s script itself, which makes it a bit funky.

For those who have this problem:
From my understanding, if you want to save specific data e.g. your UI, make sure they are all under an empty GameObject and attach your elements of UI under the empty GameObject.
Then attach the above script to the empty GameObject, which will save those things to the next scene. (Make sure the next scene doesn’t have an UI in the Hierachy, as it will be duplicated then upon loading).