When firing, making player speed slows down help;

I’ve been tryng to write a script within my player script that when I’m holding down fire, the players speed redudes. Sounds pretty simple to most of you oracles I am sure!

var canMove : boolean = false;
var maxSpeed = 4;
var minSpeed = 2;

function Update(){

    if (Input.GetButtonDown("Fire1") && canMove == false);{

        var xMove : float = Input.GetAxis("Horizontal") * Time.deltaTime * maxSpeed;
        transform.Translate( xMove , 0 , 0 );

        var zMove : float = Input.GetAxis("Vertical") * Time.deltaTime * maxSpeed;
        transform.Translate( 0 , 0 , zMove );
        InvokeRepeating("Shoot", .1, rateOfFire);
    }
        
        
   if (Input.GetButtonUp("Fire1") && canMove == true);{
        var xMove : float = Input.GetAxis("Horizontal") * Time.deltaTime * minSpeed;
        transform.Translate( xMove , 0 , 0 );

        var zMove : float = Input.GetAxis("Vertical") * Time.deltaTime * minSpeed;
        transform.Translate( 0 , 0 , zMove );
        CancelInvoke("Shoot");
        }

I am struggling, taking note from an earlier answer, I saved the speeds as varaibles which I can change throughout script. I also don’t understand Floats to well, as false/true seem to confuse me after reading through script examples. I think my logic is correct, but again i’m still learning!

Any help is greatly appreciated!

You have the right idea, the problem is that I have no idea what canMove is doing. My guess is that your character is struggling to move well at all right now? I’m going to suggest that you rewrite most of this (don’t worry I’m going to help). Here’s an example with comments:

@RequireComponent(CharacterController);
//Trust me, if you want your character to collide with anything,
//you want a character controller.

var canMove = true;
//Not sure what this variable is for, but I left it in there for you.
var maxSpeed = 4;
var minSpeed = 2;

function Update(){

    var curMoveMultiplier : float = 0;
    //we will use this value as our speed.

    if ( Input.GetButton("Fire1") ) {
    //Are we firing?

        curMoveMultiplier = minSpeed;
        //set our speed to the slower speed.
        if( !IsInvoking("Shoot") )
        //If we aren't' shooting then start
            InvokeRepeating("Shoot", .1 , rateOfFire);
    }
    else {
         curMoveMultiplier = maxSpeed;
         //otherwise, set the speed to our max speed.
         if(IsInvoking("Shoot"))
             CancelInvoke("Shoot");
    }
    if ( canMove ) {  //Can we move?
        var moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical") );
        //Create our move direction based on user input.
        moveDirection = moveDirection.normalized;
        //normalize it so you can't move faster diagonally.
        moveDirection *= curMoveMultiplier * Time.deltaTime;
        //multiply by the speed and the Time.deltaTime
        moveDirection = transform.TransformDirection(moveDirection);
        //take if from local space and put it in world space.

        var controller : CharacterController = GetComponent(CharacterController) as CharacterController;
        //Get the character Controller.
        controller.Move(moveDirection);
        //Move the character controller.
    }
}