player name not showing?

So im making a overhead name for my characters and namestring is synchronizing between client and server the only problem is even though i have overheadname.text = namestring in the command the overhead name text is not changed. am i missing a component on the overheadname text that would allow it to be synchronized in multiplayer? or is there some kind of programming iv’e missed?

the server can see the name but other clients cant see the name that the client has changed

namestring is a syncvar

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Networking;

public class PlayerAttack : BattleControl
{
    public float timeBetweenattacks;
    public float attackrange;
    public Text targetselect;
    private bool hastarget;
    private bool targetselecton;
    bool enemyisinrange;
    BoxCollider hitbox;
    bool counterstart;
    public GameObject[] enemylist;
    // Use this for initialization





    // sets the starges of the dash
    IEnumerator dashstarter()
    {
        if (dashhelpertwo == true)
        {
            dasheffect.SetActive(true);
            GetComponent<Battler>().dashstart = false;
            attackanimaton.SetBool("dash", true);
            dashnow = true;
            yield return new WaitForSeconds(10f * Time.deltaTime);
            attackanimaton.SetBool("dash", false);
            dashnow = false;
            dashforward = false;
            dashleft = false;
            dashbackward = false;
            dashright = false;
            dasheffect.SetActive(false);
            attackanimaton.SetInteger("Dashtype", 0);
            yield return new WaitForSeconds(dashspeed);
            GetComponent<Battler>().dashstart = true;
        }

    }







    //sets the stages of the attack
    IEnumerator attack()
    {
        GetComponent<Battler>().timerstart = false;
        attackanimaton.SetBool("attacker", true);
        attacksound.Play();
        enemyisinrange = true;
        yield return new WaitForSeconds(1.0f*Time.deltaTime);
        attackanimaton.SetBool("attacker", false);
        yield return new WaitForSeconds(attacktime);
        GetComponent<Battler>().timerstart = true;
        canmovebackwards = true;
        canstrafe = true;
        canmove = true;

    }


    void OnTriggerEnter(Collider other)
    {
        if (!isLocalPlayer)
        {
            return;
        }
        target = other.transform;

        if (Input.GetMouseButtonDown(0) && GetComponent<Battler>().attacktimer.fillAmount == 1 && other.gameObject.CompareTag("Battler"))
        {
            if (target == transform || other == gameObject)
            {
                return;
            }
            Debug.Log(other);
            hitsound.Play();
            Cmdhitgraphic();
            other.GetComponent<Battler>().takedamage(attackDamage);
            other.GetComponent<EnemyControl>().takedamage(attackDamage);
        }
    }

      void OnTriggerStay(Collider other)
    {

        if (!isLocalPlayer)
        {
            return;
        }
        target = other.transform;

        if (Input.GetMouseButtonDown(0) && GetComponent<Battler>().attacktimer.fillAmount == 1 && other.gameObject.CompareTag("Battler"))
        {
            if(target == transform || other == gameObject)
            {
                return;
            }
            Debug.Log(other);
                hitsound.Play();
                Cmdhitgraphic();
                other.GetComponent<Battler>().takedamage(attackDamage);
                other.GetComponent<EnemyControl>().takedamage(attackDamage);
        }


     }


    void OnTriggerExit(Collider other)
    {



    }

    //Begins Dash lerp
    void dashingnow()
    {
        if (dashnow == true && dashforward == true)
            {
            attackanimaton.SetInteger("Dashtype", 1);
            transform.position = Vector3.Lerp(transform.position, transform.position + transform.forward * dashstat, 10f*Time.deltaTime);
            }
        if (dashnow == true && dashleft == true)
        {
            attackanimaton.SetInteger("Dashtype", 2);
            transform.position = Vector3.Lerp(transform.position, transform.position - transform.right * dashstat, 10f * Time.deltaTime);
        }
        if (dashnow == true && dashbackward == true)
        {
            attackanimaton.SetInteger("Dashtype", 3);
            transform.position = Vector3.Lerp(transform.position, transform.position - transform.forward * dashstat, 10f * Time.deltaTime);
        }
        if (dashnow == true && dashright == true)
        {
            attackanimaton.SetInteger("Dashtype", 4);
            transform.position = Vector3.Lerp(transform.position, transform.position + transform.right * dashstat, 10f * Time.deltaTime);
        }
    }


    [Command]
    void Cmdhitgraphic()
    {
        hitclone = Instantiate(hit, target, false);
        NetworkServer.Spawn(hitclone);
        Destroy(hitclone, 2);
    }


    //sets target
    void attacking()
    {

        if (Input.GetMouseButtonDown(0))
        {
            if (GetComponent<Battler>().attacktimer.fillAmount == 1)

            {
                canmovebackwards = false;
                canstrafe = false;
                canmove = false;
                attackanimaton.SetBool("strafe", false);
                attackanimaton.SetBool("backwards", false);
                attackanimaton.SetFloat("strafing", 0.0f);
                attackanimaton.SetFloat("Speed", 0.0f);
                StartCoroutine(attack());
            }

            {

            }
        }
    }

    void targetdeselect()
    {
        if (Input.GetMouseButtonDown(0))
        {
            target = null;
            targetselecton = true;
        }
    }


    void dashtimerstop()
    {
        if (inputcounter > 0.2)
        {
            inputcounter = 0;
        }
    }

    void startdash()
    {


        if (Input.GetKeyDown(KeyCode.W) && inputcounter == 0 && GetComponent<Battler>().dashtimer.fillAmount == 1)
        {
            dashhelper = true;
            dashforward = true;
        }

        if (inputcounter > 0.1f && dashforward == true)
        {
            if (Input.GetKeyDown(KeyCode.W))
            {
                dashhelpertwo = true;
                StartCoroutine(dashstarter());
                dashhelpertwo = false;
                inputcounter = 0;
                dashhelper = false;
                GetComponent<Battler>().attacktimer.fillAmount = 0;
            }
        }

        if (Input.GetKeyDown(KeyCode.Q) && inputcounter == 0 && GetComponent<Battler>().dashtimer.fillAmount == 1)
        {
            dashhelper = true;
            dashleft = true;
        }

        if (inputcounter > 0.1f && dashleft == true)
        {
            if (Input.GetKeyDown(KeyCode.Q))
            {
                dashhelpertwo = true;
                StartCoroutine(dashstarter());
                dashhelpertwo = false;
                inputcounter = 0;
                dashhelper = false;
                GetComponent<Battler>().attacktimer.fillAmount = 0;
            }
        }
        if (Input.GetKeyDown(KeyCode.S) && inputcounter == 0 && GetComponent<Battler>().dashtimer.fillAmount == 1)
        {
            dashhelper = true;
            dashbackward = true;
        }

        if (inputcounter > 0.1f && dashbackward == true)
        {
            if (Input.GetKeyDown(KeyCode.S))
            {
                dashhelpertwo = true;
                StartCoroutine(dashstarter());
                dashhelpertwo = false;
                inputcounter = 0;
                dashhelper = false;
                GetComponent<Battler>().attacktimer.fillAmount = 0;
            }
        }

            if (Input.GetKeyDown(KeyCode.E) && inputcounter == 0 && GetComponent<Battler>().dashtimer.fillAmount == 1)
        {
            dashhelper = true;
            dashright = true;
        }

        if (inputcounter > 0.01f && dashright == true)
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                dashhelpertwo = true;
                StartCoroutine(dashstarter());
                dashhelpertwo = false;
                inputcounter = 0;
                dashhelper = false;
                GetComponent<Battler>().attacktimer.fillAmount = 0;
            }



            if (inputcounter > 0.17)
            {
                inputcounter = 0;
                dashhelper = false;
            }

        }
         
    }
    // counts the time bewteen keys that will activate a dash
    void dashertiming()
    {
        if (dashhelper == true)
        {
            inputcounter += Time.deltaTime;
        }
    }

    // Controls strafing
    void strafe()

    {

        if (canstrafe == true)
        {
        if (Input.GetKey(KeyCode.Q))
        {
            attackanimaton.SetBool("strafe", true);
            attackanimaton.SetFloat("strafing", 1.0f);
            var x = Input.GetAxis("Horizontal") * Time.deltaTime * walkspeedstat;
                navAgent.speed = 4;
                transform.Translate(0, x, 0);
        }

            if (Input.GetKey(KeyCode.E))
            {
                attackanimaton.SetBool("strafe", true);
                attackanimaton.SetFloat("strafing", 2.0f);
                var x = Input.GetAxis("Horizontal") * Time.deltaTime * walkspeedstat;
                navAgent.speed = 4;
                transform.Translate(0, -x, 0);
            }

            else if (!Input.GetKey(KeyCode.E) && !Input.GetKey(KeyCode.Q))

            {
                attackanimaton.SetBool("strafe", false);
            }
        }
    }




    void walkbackwards()
    {
        if (canmovebackwards == true)
        {
            if (Input.GetKey(KeyCode.S))
            {
                attackanimaton.SetBool("backwards", true);
                navAgent.speed = 4;
            }

            else if (!Input.GetKey(KeyCode.S))
            {
                attackanimaton.SetBool("backwards", false);
            }
        }
    }

    //Animates basic movement
    void Animate()
    {
        if (canmove == true)
        {

            if (Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Vertical") > 0)
            {
                attackanimaton.SetBool("isAttacking", false);
                attackanimaton.SetFloat("Speed", 6.0f);
                navAgent.speed = 4;

            }

            else if (navAgent.velocity.magnitude < 1.0f && (!Input.GetKey(KeyCode.LeftShift)))

            {
                navAgent.speed = 1;
                attackanimaton.SetFloat("Speed", 1.0f);
            }
        }
    }
    //displays targeting info

    // Controls basic movement
    void movement()
    {
        if (canmove == true)
        {
            var x = Input.GetAxis("Mouse X")* Time.deltaTime* 150.0f;
            var z = Input.GetAxis("Vertical") * Time.deltaTime * walkspeedstat;



            transform.Rotate(0, x, 0);
            transform.Translate(0, 0, z);
        }


    }

    void playerlistcannotbezero()
    {
        if (howmanyplayers < 0)
        {
            howmanyplayers = enemylist.Length;


        }

    }




   void  targeter()
    {
        if (Input.GetKeyDown(KeyCode.Z))
        {
            howmanyplayers -= 1;
            targetselect.text = enemylist[howmanyplayers].gameObject.name;

            if(howmanyplayers <0)
            {
                howmanyplayers = enemylist.Length;
            }
        }
    }
    [Command]
    public void Cmdplayernameing(string namestring)
    {
        overheadname.text = namestring;
    }




    void nametheplayer()
    {
        if (Input.GetKeyDown(KeyCode.Return))
            {
            Cmdplayernameing(namestring);
        }
    }


    public override void OnStartLocalPlayer()
    {
        enemylist = GameObject.FindGameObjectsWithTag("Battler");
        howmanyplayers = enemylist.Length;
        thecamera.SetActive(true);
        thecamera.GetComponent<CameraControl>().enabled = true;
        thecamera.GetComponent<UnityStandardAssets.ImageEffects.CameraMotionBlur>().enabled = true;
        thecamera.GetComponent<CameraControl>().cango = true;
        Cursor.lockState = CursorLockMode.Confined;
        thecamera.GetComponent<CameraControl>().target = mychild;
        cameralooking = false;
        canmove = true;
        canstrafe = true;
        canmovebackwards = true;
        dashhelpertwo = false;
        dashhelper = false;
        GetComponent<Battler>().dashstart = true;
        GetComponent<Battler>().timerstart = true;
        enemyisinrange = false;
        targetselecton = true;
        GetComponent<Battler>().attacker = false;
        hastarget = false;
        targetselect.text = ("no target");
    }





    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer) {
            return; }
        nametheplayer();
        mycanvas.transform.LookAt(Camera.main.transform);
        strafe();
        walkbackwards();
        movement();
        dashertiming();
        dashtimerstop();
        startdash();
        attacking();
        Animate();
        dashingnow();
        nametheplayer();
        playerlistcannotbezero();
        targeter();
    }
    void LateUpdate()
    {
                if (!isLocalPlayer) {
            return; }
    }
}

If the namestring is a SyncVar, can you use the SyncVar hook function to get all the clients to update their huds? I think as you have it right now the Command attribute will only update the server. The “namestring” variable might get updated on clients, but nothing is telling the clients to update the UI to that new value.

I have a very cursory knowledge of UNet so forgive me if I’m off base with that.

what kind of hook would you suggest i tried putting the same

  • public void playernameinghook (string namestring)
  • {
  • overheadname.text = namestring;
  • }

as a hook but still it will not sync the overhead text portion to the client

Honestly this is not my area of expertise so I can’t say exactly. I would try console debugging to see which clients are getting which commands. As far as I know, if the clients all get their “namestring” updated via the SyncVar, that hook function should run and update the overhead text for that client object.