Not sure how to do this- destroy existing data in game obejct to prevent duplicates

Everything was working very well and I was getting excited to finally complete my project. Then I noticed that when I would open the same canvas(with a button) that I was on before, the data from the game object doubled, so I had two pieces of the same information. I would think to check if the gameobject exists, then destroy it. Only the temp variable I’m using for instatiation is local. I don’t really want to use a global variable for it. Only when I ran a test, all my menu buttons disappeared- whoops. Anyone have some thoughts? I’ll post code if needed.

I was thinking about this backwards.
First, I made tags for each type of object to be destroyed, then added them on to their respective prefabs. This function is called by the window opening script upon closing and opening.
Hope this helps someone like me.
public void DestroyObjects(string tag)
{
GameObject Obj = GameObject.FindGameObjectsWithTag(tag);
if(Obj==null)
return;
else
{
Debug.Log(Obj.Length);
for(int i=0; i< Obj.Length; i++)
{
Destroy(Obj*);*

  •  	}*
    
  •  	Debug.Log(tag + "Objects Destroyed!");*
    
  •  }*
    
  • }*