Coding the player character to run when a button is pressed?

Hi, so I’m making a 2d platformer to teach myself, I’m using super mario world for the snes as a base to keep things simple in invisioning my game.
Anyway like in mario I want to be able to press a button and the character will double his speed into a run. But using the code I found in a tutorial I am having trouble figuring out how.
Here is the part of my player script that pertains to moving on the x axis in C#, I tried to trim it down to just the parts that matter as best I could

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

    private Rigidbody2D myRigidbody;

    private Animator myAnimator;


    private float movementSpeed = 1;

    private bool attack;

    private bool facingRight;

    private bool jump;

    [SerializeField]
    private float jumpForce;

    // Use this for initialization
    void Start ()
    {
        facingRight = true;
        myAnimator = GetComponent<Animator>();
        myRigidbody = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        //Handles the player's input
        HandleInput();
    }
    // Update is called once per frame
    void FixedUpdate ()
    {
        float horizontal = Input.GetAxis("Horizontal");


        HandleMovement(horizontal);

        Flip(horizontal);

        ResetValues();
    }
    private void HandleMovement(float horizontal)
    {
        if (!this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack") && (isGrounded || airControl))
        {
            myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y); //X = -1, Y = 0;
        }

    private void HandleInput()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            jump = true;
        }

        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            attack = true;
        }

        if (Input.GetKeyDown(KeyCode.RightShift))
        {
            movementSpeed = 2;
        }
        movementSpeed = 1;
    }

    private void Flip(float horizontal)
    {
        if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
        {
            facingRight = !facingRight;
            Vector3 theScale = transform.localScale;
            theScale.x *= -1;
            transform.localScale = theScale;
        }
    }

    private void ResetValues()
    {
        attack = false;

        jump = false;
    }

    private bool IsGrounded()
    {
        if (myRigidbody.velocity.y <=0)
        {
            foreach(Transform point in groundPoints)
            {
                //Makes an array of all colliders that are overlapping the ground points
                Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround);
                //Runs through the colliders to check if we are overlapping something that isn't the player
                for (int i = 0; i < colliders.Length; i++)
                {
                    if (colliders[i].gameObject != gameObject) //If we are overlapping something else than our self
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}

As you can see I have a float called movementSpeed, which decides how fast the character goes and is declared intially as 1. I have it set in the handleInputs section that if right shift is pressed movementSpeed becomes 2 until the button is released. Unfortunately this did not work, and the internet has giving little help on making this work. DOes any body have an idea of what I can change to get the right shift to incease movementSpeed while pressed?

You mean like this?

In HandleInput() you are setting the value of movementSpeed to 2 if the shift button is pressed. Immediately afterwards you set the value of movementSpeed to 1, so this can never be 2. This is the code I’m talking about (line 66)

if(Input.GetKeyDown(KeyCode.RightShift))
{
    movementSpeed = 2;
}
movementSpeed = 1;

You can just change movementSpeed = 1 to before the if statement

movement Speed = 1;
if(Input.GetKeyDown(KeyCode.RightShift))
{
    movementSpeed = 2;
}

You’re also using FixedUpdate and Update. This could lead to some confusion and some strange behaviour later, so I would just stick to one of them.

Thats defiently something I intend to do with a future project, so you saved me some searching in the future. But what I want is not to double tap the directional button, but to press and hold the Z key on the keyboard and while its held the player runs instead of walks. The way I was trying to do this was to Increase the movementSpeed variable in my code while the Z key is held, if the is another way that works if that one is no doable I can go with that two. So any other suggests guys?

I tried this, and all it did was make the character skip in animation and maybe move ahead a fraction in an instant.
I’m starting to think my way doesn’t work, can someone please suggest how it can or an alternitive to make the movementSpeed variable increase when right shift is pressed?
I’m thinking maybe instead of changing the movementSpeed’s value to 2 I should just add 1 to it on right shift key press and then subtract it on release, what do you guys think?

I tried out your code and I got it to work.

So you need to set movementSpeed = 1 before the if statement in HandleInput, like I mentioned before.

You also needed to use Input.GetKey instead of Input.GetKeyDown. Using Input.GetKeyDown will be true on the first key press. It will not be true for subsequent frames. Check out the documentation for it.
Unity - Scripting API: Input.GetKeyDown and
Unity - Scripting API: Input.GetKey

Here’s the snippet that works

private void HandleInput()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                jump = true;
            }

            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                attack = true;
            }
            movementSpeed = 1;
            if (Input.GetKey(KeyCode.RightShift))
            {
                movementSpeed = 2;
            }
           
        }