How do you make it so that you must kill all the enemies before you can exit the level

I tried looking at some examples and other discussions but they had it so you instantly went to the next level after collecting all the coins. I want it to activate the door to the next level

Alright you want to a certain amount of enemies (1)


The number of enemies is randomly generated? (2)

Solution to 1:
Just Do the same way with coins but make the enemy send a message to the player and then he updates the number

Solution to 2:
make an object with a really big proximity and if the object didnt detects it goes to the next level

thank you