Play Again Error

Hello, I have a 2D game I coded where I put all of my end of game screens in my main gameplay scene to avoid crashing the site.

My problem is that when I load my game the first time around, all functions work as they should, however, when a player loses and tries the game again. Once they actually win. The screen ends up displaying the “Lose UI Screen” instead of the “Win UI Screen”

I’ve tried recoding a hundred times but nothing is working. Can someone check out my codes and tell me what I’m doing wrong, I genuinely want to learn.

https://playcanvas.com/editor/scene/2130673

It probably the logic in this function enablePopupInteraction2. Did you mean “==” rather than “=” on line 3?
Also every time this function is called you register another event handler function which may be causing unwanted effects.

CharacterCollision.prototype.enablePopupInteraction2 = function (popup, entity) {
    this.app.keyboard.on(pc.EVENT_KEYDOWN, (event) => {
        if ((event.key === pc.KEY_N) || (this.collidedWithhomeboundary = false)) {
            this.resetInteraction(popup);
            this.entity.sound.play('NYRKey');
        }```

I see, I didn’t really think about “==” since the condition is True or False, let me try it out.

Also in order to prevent registering events every time. Is there an alternative code you can suggest for activating the function upon pressing down the N key?

Thank you for your response, hope to hear from you again soon