How exactly can I event this properly?

The idea is to have random music play depending on whether you are in a town or exploring while having a random amount of time between each song. At first I evented this as such:
Step 1: Have switch MusicOn = on during the games initialization which autoruns on game start and sets all the switches and changes variables I want, then turns another switch on so it never turns on again.

Step 2: Have a common event that runs parallel when musicOn is on.
Spoiler: Event1
Event1.jpg

Firstly this sets a random time to wait to a variable, then waits for this amount. Next it chooses a random number between 1-5 and sets it as a variable. Next we have a conditional branch that is if isTown is on (every map has an initialization event that auto runs and erases itself at the end that does several things, but one of them will turn isTown on if it is in a town, and off it is not). Since we are in a town, this will be on so it will then choose the song based on the variable MusicRandomize. It will play this song and then wait for the amount of time the song lasts, then it will restart this process.

This works perfectly if I stay in one map, however when I move to a new map since musicOn is on, it will run this common event again. So now the song is still playing, but this event is ran again so it will start a new song eventually cutting off the old one.

To fix this, I then changed it so that it will instead run this
Spoiler: Event2
event2.jpg
This is doing the same as above, but will instead of playing it from this common event, run another common event. For example if it choose town 1 it will run this.

Spoiler: Event3
event3.jpg
This should play the song, and then switch off musicOn, that way if we change maps it will not override this song. Then wait for the length of the song, turn off the song, then turn musicOn back on, so the process can be repeated. Instead what it does is plays the song, and then nothing ever happens. The song just repeats eternally.

Does anyone have any solution to this problem or could advise is another way to event this?
All you need to do is change the order of your logic to take the long waits out.

- Wait 60
- Subtract 1 from SongLength variable
- If SongLength == 0
- - Do all your stuff to determine a new BGM
-- Set SongLength = length of music in seconds
All you need to do is change the order of your logic to take the long waits out.

- Wait 60
- Subtract 1 from SongLength variable
- If SongLength == 0
- - Do all your stuff to determine a new BGM
-- Set SongLength = length of music in seconds
This worked perfectly, thanks!~

Original thread: https://forums.rpgmakerweb.com/threads/how-exactly-can-i-event-this-properly.164955/