int to TextField and TextField to int

I’m trying to use theGUILayout.TextField to display and edit an int. But I keep getting “FormatException: Input string was not in the correct format” on what I know should work.

My code is:

x = int.Parse(GUILayout.TextField(y.ToString()));

X is an public int, set by another script elsewhere.

The following works for me and I am unable to type anything, but numbers into the textfield.

	int guiInt = 0;

	void OnGUI()
	{
		GUILayout.BeginArea(new Rect(10.0f, 10.0f, Screen.width - 20.0f, Screen.height - 10.0f));
		
		int.TryParse(GUILayout.TextField(guiInt.ToString()), out guiInt);
		
		GUILayout.EndArea();
		
	}