# Changing scenes crashes game

**URL:** <https://forum.playcanvas.com/t/changing-scenes-crashes-game/29639>\
**Category:** Help & Support\
**Tags:** ui\
**Created:** [February 9, 2023, 12:48am UTC](https://forum.playcanvas.com/t/changing-scenes-crashes-game/29639 "2023-02-09T00:48:41Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [February 9, 2023, 1:05am UTC](https://forum.playcanvas.com/t/changing-scenes-crashes-game/29639/2 "2023-02-09T01:05:21Z")

</div>

Hi @almish_subuk!

To change a scene, please use the method from your other topic.

> [@\[SOLVED\] Changing scenes results in error that shoudnt be there](https://forum.playcanvas.com/t/solved-changing-scenes-results-in-error-that-shoudnt-be-there/29633):
>
> I am making a menu for my game, and a few problems have appeared. When I launch from the main menu scene, i get no errors, until I click the button that takes me to the main scene. Here I get some errors regarding my shooting scipt, but when i launch from the main scene, I get no errors. Another error is that when my player dies, he is sent to the main menu, but the script that took him there is still running, so when you click the script tries to run but fails and outputs a bunch of errors. Cou…

Not sure why you create a new topic about this problem, but I think it’s related to events.

If you use an event, you have to make sure you clean up the event if you change the scene. Otherwise the system is still listening to the event, even if not everything for the event exist in the new scene, which result in an error.

I’m not exactly sure how to do this correctly, but based on an event in from you script it should be something like below.

```javascript
// create event
app.mouse.on("mousedown", function () {
    app.mouse.enablePointerLock();
    this.shoot();
    console.log("initlal gjs0");
}, this);

// remove event
this.on('destroy', function() {
    app.mouse.off("mousedown", function () {
        app.mouse.enablePointerLock();
        this.shoot();
        console.log("initlal gjs0");
    }, this);
});

```

---

_[View the full topic](https://forum.playcanvas.com/t/changing-scenes-crashes-game/29639)._
