while tries != 0
will be always true for the events you are not looking for, and _input
fires on every event, that results on an infinite loop for almost any action.
Change that while tries =! 0
for an if tries != 0
_input
gets an atomic event, and should be used to process a single event, do not use loops inside or complex processing or you will freeze the game during input handling, use it to set variables and process your game logic in _process
or _physics_process
instead.
Also make use of breakpoints to see what is happening when conditions do not work as expected.