I honestly can't understand why it doesn't work ( IsLocalPlayer )

Hi all.
This may seem like a dumb question to most people, but I can’t figure out what my mistake is.
(This is probably the first time in my life that I have decided to ask for help).

What the problem is:
I recently started using “Netcode for GameObjects”.
And for the sake of testing, I decided to do a simple player move.
As I understand it, to check if a player is local or not, there is a variable: “IsLocalPlayer”
And it works but the player who is connected can’t move although islocalplayer == true

public class PlayerController : NetworkBehaviour
    {
        [SerializeField] private TextMeshProUGUI inputFText;
        [SerializeField] private TextMeshProUGUI inputRText;
        [SerializeField] private TextMeshProUGUI islocalText;


       
        private Rigidbody _rigidbody;
        private float speed  =5f;
        private void Awake()
        {
            _rigidbody = GetComponent<Rigidbody>();
           
        }


        private void Update()
        {
            islocalText.text = IsLocalPlayer.ToString();

            if (!IsLocalPlayer)
                return;
           
            float moveF = Input.GetAxisRaw("Vertical");
            float moveR = Input.GetAxisRaw("Horizontal");
               
            inputFText.text = $"InputF: {moveF}";
            inputRText.text = $"InputR: {moveR}";
               
            Vector3 direction = transform.forward * moveF + transform.right * moveR;
            _rigidbody.velocity = direction * speed;  
        }
    }

I displayed the data of the two variables on the game screen.
And if you believe them, the player connected when you press the button responsible for: Input.GetAxisRaw(“Vertical”); ( moveF )
The variable moveF = 1 || moveF = -1 but the player does not move

You have no NetworkVariables that sync with the Server/Host. Everything you are doing is not syncing anywhere. I recommend you go watch some tutorials.

1 Like

If you want the client movement to be synched and want the client to have authority over movement (as your code implies), note that that means the client needs a ClientNetworkTransform component. If you have a NetworkTransform instead, only the server can change the transform, which would explain the player not moving.

2 Likes

Thanks man, using ClientNetworkTransform saved me

1 Like