enabling and disabling components script not working

Hi, Im new to c# and coding in general and I’ve made myself a script to effectively switch between two different types of movement (walking and flying), but it wasn’t working as I could only switch to flying and not back so I edited it and now none work… I’m sure I’m missing something obvious or because I’m not very good at scripting at all :frowning:

using UnityEngine;
using System.Collections;

public class EnableScripts : MonoBehaviour { 
	private bool flymode;
	private bool walkmode

	void Update () {
	if (Input.GetKeyDown ("f"))
			GetComponent<Move> ().enabled = true;
		GetComponent<SpeedUp> ().enabled = true;
		GetComponent<WalkScript> ().enabled = false;
		flymode = true;
		{
	if (Input.GetKeyDown ("f") && flymode == true)
		    GetComponent<Move> ().enabled = false;
		GetComponent<SpeedUp> ().enabled = false;
			GetComponent<WalkScript> ().enabled = true
		flymode = false;
	 
  }
 }
}

Your code is quite messy, there are typos, and you didn’t use brackets to delimit the if blocks, so there isn’t much to change. However, always use GetComponent in Start or Awake, never in Update. You only need to get references to these scripts once, not every frame.

using UnityEngine;
using System.Collections;
 
public class EnableScripts : MonoBehaviour 
{ 
    // Start in walk mode
    bool flymode = false;
    Move move;
    SpeedUp speedUp;
    WalkScript walk;


    void Awake()
    {
        // Get all references to your other components here
        move = GetComponent<Move>();
        speedUp = GetComponent<SpeedUp>();
        walk = GetComponent<WalkScript>();
    }

    void Update () 
    {
        // If player hits f...
        if (Input.GetKeyDown("f"))
        {
            // ... while they're walking, then start flying
            if (!flymode)
            {
                move.enabled = true;
                speedUp.enabled = true;
                walk.enabled = false;
                flymode = true;
            }
            // Else start walking again
            else
            {
                move.enabled = false;
                speedUp.enabled = false;
                walk.enabled = true;
                flymode = false;
            }
        }
    }
}