A game object can only be in one layer. The layer needs to be in the range [0...31]

I am following a series of tutorials as closely as I can, but I am having a problem. I think this may be the source. When I have 2 players in the scene running in different instances of the game, one is supposed to be local, and the other is supposed to be remote. however, both stay local, and it gives me the error “A game object can only be in one layer. The layer needs to be in the range [0…31]”
Here is my full script:

using UnityEngine;
using UnityEngine.Networking;

public class PlayerSetup : NetworkBehaviour {

[SerializeField]
Behaviour[] componentsToDisable;

[SerializeField]
string remoteLayerName = "RemotePlayer";

Camera sceneCamera;

void Start()
{
    if (!isLocalPlayer)
    {
        DisableComponents();
        AssignRemoteLayer();
    }

    else
    {
        sceneCamera = Camera.main;
        if (sceneCamera != null)
            Camera.main.gameObject.SetActive(false);
    }

    RegisterPlayer();

}

void RegisterPlayer()
{
    string _ID = "Player " + GetComponent<NetworkIdentity>().netId;
    transform.name = _ID;
}

void AssignRemoteLayer()
{
    gameObject.layer = LayerMask.NameToLayer(remoteLayerName);
}

void DisableComponents()
{
    for (int i = 0; i < componentsToDisable.Length; i++)
    {
        componentsToDisable*.enabled = false;*

}
}
void OnDisable()
{
if (sceneCamera != null)
sceneCamera.gameObject.SetActive(true);
}
}

I know its bit a late reply. But might be helpfull for others. So This error comes when Layer is missing. Goto Edit > Project Settings > Tags and Layers You need to add Layers Name which you are using.

@overseer314
I had the same problem with brackies tutorial series :smiley:
I solved it by adding this is the Start()

mask = LayerMask.NameToLayer("RemotePlayer") ;

The other way of doing this is simple and easy
By declaring a enum playerLayers {LocalPlayer=8,RemotePlayer=9}
Then assigning the gameobject.layer the value as follows
Gameobject.layer = (int)playerLayers.RemotePlayer
The remote player value is used in your case.
I hope you guys like this solution

I just started watching Brackeys and got the same problem, got it fixed simply by hard coding the layer name in the function

void AssignRemoteLayer()
{
gameObject.layer = LayerMask.NameToLayer(“RemotePlayer”);
}

I guess the variable is not being set on start thus the error

Old post, but this also happens if you try to assign a GameObject’s layer to a Layer Mask, a silly mistake but it won’t come up as an error in the compiler.

I do this mask = LayerMask.NameToLayer(“RemotePlayer”) ;
@ AhmedSabry19
but i do not add layer in the layer list so i have this error but when i add the layer solved.