NetworkManager component is your custom class? There is just a built-in class with the same name that corresponds to Unity Networking. (I am not talking about Find function, but about GetComponent)
If it is your custom class, then I would recommend you to change name.
If you wanted to call this built-in class of networking, then there is no such variable as HPBar in this class. You probably want to get this from another place, but not from NetworkManager.
This code will get component/script of class NetworkManager on the object with tag “NetworkManager”. That is fine. But next part of the line:
...HPBar.GetComponentInChildren<Slider>();
Calls for HPBar variable in the class NetworkManager. The class doesn’t have such variable inside (It might be that another class on the object stores this variable). So, a question rises, where does this variable “HPBar” locate?
Again, if NetworkManager is a class that you have made, just tell me.
No i tjekked that, the script contains that value, and im also able to change all the components i get from there.
thats why the error is wierd, because all the objects work just fine
What is in the HPBar? I mean, are you sure that the component Slider should be found in children, but not on the object itself. I just dont know what exactly you put in the variable. Check please that the object you put in the variable is not the object with Slider component.
Yeah, probably it is correct, but check anyway.
Next step, I would like to ask you to debug the variable. After the block of code, that gets values from another script, type
Debug.Log(HPBar.value);
And look what it will show. It may show the value, the same error, but pointing at another line(it may still throw the same error, but only line will be different. so, pay attention to this), or it may show nothing. Debug will not work. It means that the problem is with photonView.
Sorry, I cannot tell you immediately where is the error, because I dont know how your project is constructed and maybe y. But I know what we should look at. So, sooner or later we will find the source of error.
You don’t have to change the name since Unity’s is in the UnityEngine.Networking namespace and since this appears to be using Photon I can’t imagine OP will be including it anywhere in their code.
That being said - line 116 in PlayerNetwork stuff. HPSlider is null which means your huge, compound find on line 60 failed (or the HPSlider was destroyed at some point). Break down line 60 into multiple lines to see if it succeeds or where it fails first off. If that is working (I’d still break it down anyway) then start working towards where it might have been destroyed.
To add to Kelso’s reply: either HPSlider was not found in line 60, OR possibly you’re calling “GetShot” on PlayerNetworkStuff before Start() is called. For example, if PlayerNetworkStuff is disabled in the hierarchy, Start() will never get called and HPSlider will still be null.
I found the error, it was that the hpbar stuff was only set on the local player and not the players over the network, so when it tries to acces it it returned the error.
So short when i shot a player, that player tried to acces my players hp bar and failed