Is there a way to stop objects from duplicating?

I have two objects, GameManager and Text, which control the game’s scorekeeping and GUI text for the player respectively. I had an earlier issue where if the player went to level two, died, and restarted, GameManager and Text would duplicate. I fixed that by adding a bool restart, which is always set to true:

        public bool restart = true;
		if (restart) {
			DontDestroyOnLoad(gameObject);
		}

I’ve come across a new problem, which is if the player dies on level 1 then these objects will be created again and overlap. I was wondering if there’s a way to prevent this from happening, maybe by loading GameManager and Text from a script rather than having them in the inspector. I read a post that suggested instantiating both of them in a script and attaching that to an empty gameobject, but the same issue persisted along with the text not changing. Any help would be appreciated.

this sounds like you are making it more complicated than it needs to be. just put the DontDestroyOnLoad in the awake function on each object you dont want to be destroyed. then if the player dies and it goes back to the main level your objects wont be destroyed and you just keep reusing the existing ones. when your not using them just deactivate them, dont destroy them. how are you instantiating the objects to begin with? it sounds like you have a script instantiates them in the main level, that would be why its duplicating.