Best way to attatch text to text script c#

So I have a script that writes how much gold the player has, however when I load the scene (using a dontdestroyonload) I get an error because I simply made the text public and dragged in the UI element I wanted it to be. But when I reload the scene it doesn’t know what element I dragged in and returns an error. What is the best way to fix this?

Thanks for trying to help! So you know how a public variable shows up in the inspector? When I reload the scene it shows it being empty. Does that help?

you can use GameObject.find(“text”) in start when it loads the scene.