Jump script malfunction

For some unknown reason, in this project…
…when entering another stage while playing the game, the jumping portion of the movement script doesn’t work properly, and it only gives this error:

[[movementone.js?id=126367797&branchId=91c78a18-6699-4f19-931e-81c8b28eaebd:69]](https://playcanvas.com/editor/code/1052896?tabs=126367797&line=69&col=27&error=true): Uncaught TypeError: Cannot read properties of undefined (reading 'applyImpulse')

TypeError: Cannot read properties of undefined (reading 'applyImpulse')
at Movementone.onKeyDown (https://launch.playcanvas.com/api/assets/files/Misc/scripts/movementone.js?id=126367797&branchId=91c78a18-6699-4f19-931e-81c8b28eaebd:69:27)
at Keyboard.fire (https://code.playcanvas.com/playcanvas-1.61.3.js:615:18)
at Keyboard._handleKeyDown (https://code.playcanvas.com/playcanvas-1.61.3.js:10968:9)

I’ve gone through the code and nothing seems to be wrong with it, even though it highlights this part of it:

this.entity.rigidbody.applyImpulse(0, 10, 0);

Here’s the whole script:

Hi @butternyke!

On line 20 of your script you create an event. You need to remove this event when you for example change the scene. Below an example.

// listen for the player:move event
this.app.on('player:move', onPlayerMove);

// remove player:move event listeners when script destroyed
this.on('destroy', function() {
    this.app.off('player:move', onPlayerMove);


The error message “Uncaught TypeError: Cannot read properties of undefined (reading ‘applyImpulse’)” is being thrown in the ‘movementone.js’ file at line 69. The issue is that the code is trying to access the ‘applyImpulse’ property of an object that is currently undefined. To fix the problem, you should make sure that the object is properly initialized before attempting to call its ‘applyImpulse’ method. Also, check for any possible syntax errors or typos that may be causing the issue.