Can't see anything wrong, but with incomplete code I can't really tell well the problem lies. One thing that comes to my mind is having some kind of default case that plays the last track no matter what happens.
At any rate, instead of one central switch-case, I'd instead suggest linking the music to the room more directly.
For example, you could create an object called
obj_bgm_player
and doodle some placeholder note or other sprite to make it easily recognisable (make it invisible, though).
Then, in object Variable Definitions add a "bgm" variable with "Asset" type, and in options selecting "Sounds" as the only option. Also, type "undefined" as the default value.
Then, in Room Start code, you could add something like:
GML:
if (is_undefined(bgm)) {
audio_stop_all();
// if "bgm" is undefined, it's interpreted as no music playing at all
} else if (!audio_is_playing(bgm)) {
audio_stop_all();
audio_play_sound(bgm, 1000, true);
} else {
// if "bgm" is already playing, just keep playing it
}
Such code should be easy enough to expand upon if you e.g. needed to implement a muting/unmuting functionality.
With this, you can directly associate each room with specific background music from within the room itself, and if there are multiple rooms with same track, the BGM will play without restarting when you move between them.
Of course, if there are more advanced BGM-handling scenarios (e.g. choosing a room music based on a global variable), you might need to add a more complex mechanism. That's also why the music handling is in the Room Start code - that way you have a chance to choose the appropriate BGM in Instance Creation Code before Room Start is called.