Loading Scene (394031)

Hi, I have a question here.
I have 2 Scenes. In the game, I will need to travel between Scene A and Scene B frequently. In Scene A, I store the variables needed in a javascript file and apply the following:

function Awake () {
DontDestroyOnLoad (this);
}

When I reach Scene B, the javascript file is there. But when I go back to Scene A, the gameObject(javascript file) duplicates into 2.

How can I solve this problem? Thanks.

I see two options:

(a) Create a third scene that will actually be the very first one loaded, and in that scene you create this persistent data storage object. Being as you’ll never go back to this “loader” scene you’ll never create a second copy of this object, problem solved.

(b) Have this data storage object look for other copies of itself when it’s created. If none are found then all is good (first load). If it finds a copy of itself already in existence then the new one that was just created should quietly destroy itself so it goes away.