MZ Making player follow mouse

Hello! I am new to coding so I decided to take up the challenge of trying to code a mechanic in which the player would follow the mouse's coordinates. I figured out how to make the player move to certain coordinates on the map, but my main struggle is how to convert touch input into coordinates to then have that character follow it.

Here's the code I have made so far:


Code:
◆Script:{
:      :
:      :const TouchInput_onMouseMove = TouchInput._onMouseMove
:      :TouchInput._onMouseMove = function(event) {
:      :    $gameVariables.setValue(55, Graphics.pageToCanvasX(event.pageX))
:      :    $gameVariables.setValue(56, Graphics.pageToCanvasX(event.pageY))
:      :    TouchInput_onMouseMove.call(this, event)
:      :}
:      :
:      :}
◆Loop
  ◆If:Script:$gamePlayer.x == $gameVariables.value(55) && $gamePlayer.y == $gameVariables.value(56)
    ◆Break Loop
    ◆
  :Else
    ◆Script:this.moveStraight(this.findDirectionTo($gameVariables.value(55), $gameVariables.value(56)))
    ◆
  :End
  ◆
:Repeat Above

What happens when the code is in action is that it says "this.findDirectionTo" is not a function even though it worked separately when I used code

Code:
◆Loop
  ◆If:Script:$gamePlayer.x == 30 && $gamePlayer.y == 2
    ◆Break Loop
    ◆
  :Else
    ◆Set Movement Route:Player (Wait)
    :                  :◇Script:this.moveStraight(this.findDirectionTo(30, 2))
    ◆
  :End
  ◆
:Repeat Above

My main goal is to convert touch input's coordinates into coordinates that the player follows automatically. I then plan after the player and the mouse are in the same position that player will no longer follow the mouse. I don't really know what I'm doing wrong or if It's really possible. Just experimenting with possibilities here!
Because in the first example "this" is the Game Interpreter while in the second you're putting this inside a move route under the Player so it refers to the player. findDirectionTo() is game character function

Original thread: https://forums.rpgmakerweb.com/threads/making-player-follow-mouse.174646/