Need Help Identifying Null

I can’t quite figure out why the GUItextbox won’t change values like I believe it should (upon pressing space). I eventually want in-game events to change the text displayed in the GUItextbox and this is my broken down version of it. It tells me that the text box.myText is never being assigned and the “hello” is not becoming “You pressed space!”.

public class textbox : MonoBehaviour {

 GUIText myText;
// Use this for initialization
void Start()
{
	GameObject guiText = new GameObject("SomeGUIText");
	Instantiate(guiText);
	GUIText myText = guiText.AddComponent<GUIText>();
	myText.transform.position = new Vector3(0.02f,0.1f,0f);
	myText.guiText.text = "Hello";

}
// Update is called once per frame
void Update () {

	if (Input.GetKeyDown (KeyCode.Space)) {

		myText.guiText.text = "You pressed space!";

			}



}

}
`

You are declaring ‘myText’ twice…once at the top of the file and once in Start(). The declaration on line 7, is local to Start() and will disappear when you return from Start(). This declaration hides the variable on line 1. So the myText that is available in Update() is never initialized. You can fix the problem by simply removing the GUIText on line 7:

 myText = guiText.AddComponent<GUIText>();

Also note that line 19 can be simplified (slight performance improvment) to:

 myText.text = "You pressed space!";