!islocalplayer not working

Basically i need to know why this isn’t working.

public class classselect : NetworkBehaviour {

public GameObject player;

public bool test = true;

public float wait;

public Camera Vcam;

void Update() {

    if (!isLocalPlayer)
    {
        return;
    }
    if (wait > 0)
    {
        wait -= 0.1f ;

    }
    if (wait < 0)
    {
        test = false;
       
    }
   

}
void OnDisconnectedFromServer(NetworkDisconnection info)
{
    test = true;
    Vcam.enabled = true;
}
void OnGUI() {
    if (!isLocalPlayer)
    {
        return;
    }
    if (test == true)
    {
        if (GUI.Button(new Rect(100, 150, 50, 20), "Test"))
        {
            Instantiate(player);
            Vcam.enabled = false;
            wait = 2;
        }
        
    }
}

}

So i fine in the player object from the classselect and that works fine.

Now in the movement script for the player game-object it doesn’t work.

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.Networking;
[RequireComponent(typeof(CharacterController))]
[AddComponentMenu(“Camera-Control/Mouse Look”)]
public class charactercontroller :NetworkBehaviour {

public bool run;
private Animator anim;
public bool idle;
public bool runshoot;
public bool shoot;
public float speed = 10f;
[SyncVar]
public float health;
public Transform player;
public Rigidbody RB3D;
public bool sword1;
public bool roll;
public float stamina = 100f;
public float maxstmaina;
public Transform shot;
public Rigidbody projectile;
[SerializeField]
protected Texture2D
healthBarTexture;
public Texture2D staminabar;
public float healtime = 0f;
public Camera pcam;
public GameObject classest;

void Start()
{
    anim = gameObject.GetComponent<Animator>();
    idle = true;
}
void FixedUpdate()
{
    if (!isLocalPlayer)
    {
        return;
    }
    
	//Handles Movement
	CharacterController controller = GetComponent<CharacterController>();
	//Creates forward vector3
	Vector3 forward = transform.TransformDirection(Vector3.forward);
	//Creates right vector3
	Vector3 right = transform.TransformDirection(Vector3.right);
	float curSpeed = speed * Input.GetAxis("Vertical");
	controller.SimpleMove(forward * curSpeed);
	float curspeed2 = speed * Input.GetAxis ("Horizontal");
	controller.SimpleMove(right * curspeed2/2);
	

    healtime -= 0.01f;
    if (healtime < 0) {
        healtime = 0f;
    }
    if(health > 200)
    {
        health = 200;
    }
    if (Input.GetKeyDown(KeyCode.Alpha1) && healtime <= 0)
    {
        health += 40;
        healtime = 15;
    }
    maxstmaina = stamina;
    if ( stamina > maxstmaina)
    {
        stamina = maxstmaina;
    }
    if(stamina > 1500)
    {
        stamina = 1500f;
    }
    stamina += 5f;
    anim.SetBool("Run", run);
    anim.SetBool("Idle", idle);
    anim.SetBool ("shoot",shoot);
    anim.SetBool("attack",sword1);
    anim.SetBool("Roll", roll);
    anim.SetBool("Runshoot",runshoot);
  
    if (Input.GetKey(KeyCode.W))
    {
        Debug.Log("WTF");
        speed = 35f;
        run = true;
        idle = false;
       
    }
    
    if (Input.GetKeyUp(KeyCode.W))
    {
        speed = 0f;
        run = false;
        idle = true;
    }
	if (Input.GetKey(KeyCode.S))
	{
		speed = 35f;
		run = true;
		idle = false;
		
	}
	
	if (Input.GetKeyUp(KeyCode.S))
	{
		speed = 0f;
		run = false;
		idle = true;
	}
	if (Input.GetKey(KeyCode.D))
	{
		speed = 35f; 
		run = true;
		idle = false;
		
	}
	
	if (Input.GetKeyUp(KeyCode.A))
	{
		speed = 0f;
		run = false;
		idle = true;
	}
	if (Input.GetKey(KeyCode.A))
	{
		speed = 35f;
		run = true;
		idle = false;
	}
	
	if (Input.GetKeyUp(KeyCode.D))
	{
		speed = 0f;
		run = false;
		idle = true;
	}
    if (Input.GetKey(KeyCode.R) && stamina > 400f)
    {
		controller.SimpleMove(forward * speed * 2);
        speed = 35f;
        run = false;
        roll = true;
        idle = false;
        stamina -= 10f;
    }
    if (stamina < 500f)
    {
        roll = false;
    }
    if (Input.GetKeyUp(KeyCode.R))
    {
        roll = false;
        idle = true;
    }
    if (Input.GetMouseButton(1) && run == true)
    {
        runshoot = true;
    }
    if (Input.GetMouseButtonUp(1) && run == false)
    {
        runshoot = false;
    }
    if (Input.GetMouseButton(1))
    {
        shoot = true;
        idle = false;
    }
    if (Input.GetMouseButtonUp(1))
    {
        shoot = false;
    }
    if (Input.GetMouseButton(0))
    {           
        sword1 = true;
        idle = false;
    }
    
    if (Input.GetMouseButton(1) && Input.GetKey(KeyCode.W))
    {
        runshoot = true;
        run = false;
        shoot = false;
    }
    if (Input.GetMouseButtonUp(1) || Input.GetKeyUp(KeyCode.W))
    {
        runshoot = false;
        idle = true;
    }
    
}
                                                                                                                                                                                                                                  

void ApplydamageP(float damage)
{
    if (!isLocalPlayer)
    {
        return;
    }
    health -= damage;
    Debug.Log("Damage");
    if (health <= 0)
    {
       // classest.SetActive(false);
    }

}
void OnGUI()
{
    if (healthBarTexture != null)
    {
        GUI.color = (Color.red);
        GUI.DrawTexture(new Rect(600, 570, 1.5f * health/2, 15), healthBarTexture);
    }
    if(staminabar != null)
    {
        GUI.color = (Color.cyan);
        GUI.DrawTexture(new Rect(600, 550, 1.5f * stamina /15, 15), staminabar);
    }
    GUI.color = (Color.white);
    GUI.Label(new Rect(20, 570, 500, 100), "" + (Mathf.RoundToInt(healtime)));
}

}

Now the issue is that the new instantiated gameobject is not set to localplayer for some reason so it returns and ignores the rest of the script.

What i need to know is how do i set it to local player.

isLocalPlayer doesn’t work because the server has no way of telling that the instantiated object is the local player.
I think what you’re looking for is to be able to manually spawn the player gameobject. So you might want to try searching that, and there are plenty of guides available on how to do that so that the server knows what the local player is.

I hope this helps.