FormatException: Input string was not in the correct format System.Int32.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Int32.cs:629) Multijugador.Update () (at Assets/Multijugador.cs:31)

have idea how to fix error and script explication plis

using UnityEngine;
using UnityEngine.UI;

public class Multijugador : MonoBehaviour

    public string MyIP = "";
    public int MyPort = 1;
    public string HostIp = "";
    public string HostPort = "";
    public int MaxConnections = 8;
    public Text ServerIp;
    public Text ServerPort;
    public Text MaxConnections2;
    public Text Myip2;
    public Text MyPort2;

    void Start()
        MyIP = Network.player.ipAddress;

    void Update()
        HostIp = ServerIp.text;
        HostPort = ServerPort.text;
        Myip2.text = "Tu ip: " + MyIP.ToString();
        MaxConnections = int.Parse(MaxConnections2.text);
        MyPort = int.Parse(MyPort2.text);

        int result = 0;
        if (int.TryParse(MaxConnections2.text, out result))
            MaxConnections = result;
        int result2 = 0;
        if (int.TryParse(MyPort2.text, out result2))
            MyPort = result2;

    public void Conectar()
        Network.Connect(HostIp, HostPort);

    public void CrearServer()
        Network.InitializeServer(MaxConnections, MyPort, true);

If you enter something that is not an int, it’ll throw an error.
You should :

  • Use an InputField, not just a text
  • Set its content type to “integer number”, it’s in the InputField parameters
  • Subscribe your conversion method to the InputField event (there’s a “Value Changed” event) so that it doesn’t do this every frame, but only when data is entered
  • You can do this in the editor, or by code like in the example provided here.