What is wrong with my script?


So I was trying to make a script so that when applied to a character would make the character follow the Player, but only if the Player is close to that character. I am, however, quite new at javascript, so of course there’s something wrong with my script, but I don’t know what. Any help would be appreciated!

var distance;
var Player : Transform
function Update (){
  distance = Vector3.Distance(Player.position, Transform.position)
  if (distance < 20){
    target = GameObject.FindWithTag("Player").tranform; //target the player

function Update () {
  myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
  Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);

  //move towards the player
  myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;


target = GameObject.FindWithTag(“Player”).tranform;