Issue when holding keyboard input as the scene restart

Hello, I’ve been trying to make a 2 player platformer game (with local control WASD and arrow keys).
and I’ve look at the basic platformer control example on phaser website.
However I came across a little problem when I try to restart the scene.

So what I’m trying to get is, when the players falls out of the map → scene will restart → if player still holds the move input → player keeps moving after scene reset.
However when I hold two input (both player move input / move and jump input) only the last input that is pressed get registered after scene restart.

example:
player 1 move input right(hold) → player 2 move input right(hold) → player fall → scene restart → only player 2 move input got registered.

so even if I’m holding both player move input after the scene restart only one of them is registered as pressed.
is there anyway to get both player input after restart?

Here is the control code snippet:
In Create

player_control = context.input.keyboard.addKeys({ 
        'up': 'up', 
        'down': 'down',
        'left': 'left',
        'right': 'right' });   
    
player2_control = context.input.keyboard.addKeys({ 
        'up': Phaser.Input.Keyboard.KeyCodes.W, 
        'down': Phaser.Input.Keyboard.KeyCodes.S,
        'left': Phaser.Input.Keyboard.KeyCodes.A,
        'right': Phaser.Input.Keyboard.KeyCodes.D });

In Update

/* Player 1 Control */
if(player_control.left.isDown){
    player.body.velocity.x = -moveVelocity;
    player.flipX = true;
}
else if(player_control.right.isDown){
    player.body.velocity.x = moveVelocity;
    player.flipX = false;
}
else{
    player.body.velocity.x = 0;
}

/* Player 2 Control */
if(player2_control.left.isDown){
    player2.body.velocity.x = -moveVelocity;
    player2.flipX = true;
}
else if(player2_control.right.isDown){
    player2.body.velocity.x = moveVelocity;
    player2.flipX = false;
}
else{
    player2.body.velocity.x = 0;
}

Could you show the whole scene code?

Does Player 2 key input work if you release the key and press again?

Here’s the code
https://pastebin.com/uxZp65Zg

If the button is released then press again the entire control have no problem, what I’m trying to get however is something like this:
player1 & player2 press and hold move right input → both player move to the right → player falls out of the map → scene restart (input key is still pressed) → both player move to the right

but when I try to run the game, what I get is something like this:
player1 & player2 press and hold move right input → both player move to the right → player falls out of the map → scene restart (input key is still pressed) → 1 player will move while the other doesn’t

when I try to log the input. 1 input key isDown value is true, while the other is false even though I’m still pressing both input.
So basically I want the input key that I pressed and hold before the scene restart to persist after the scene restart.
I Hope it make sense and thank you for the response :grin:

We solved this. The issue is that

  • The OS sends a repeating keydown event for only the last key pressed
  • Key objects are destroyed when a scene is shutdown

The solution is to reuse the same Key objects across scene cycles, by removing and readding them.

Thank you samme :pray: