#NETCODE MULTİPLAYER

1 messages · Page 1 of 1 (latest)

tame cobalt
#

I am coding a health system with Netcode but the code I wrote works on the host but not on the client. (In short, the host can lower the health of the client but the client cannot lower the health of the host). Am I missing something?

alpine river
#

You cant change network variables on the client

#

Network variables can only be modified by the server

#

You need to send a ServerRpc from the client that modifies the health value

#
[ServerRpc]
private void DecreaseHealthServerRpc(int amt) 
{
  playerHealth.Value -= amt;
}

Then when your code hits the other object, just call this member function on the health system you wish to apply damage to

#

By the way, remember that classes should only have one distinct ability. a health system should only care about health, and not shooting/input. This logic should be moved into a player class, or somewhere if you want to follow the best practices, and ensure things scale the best they can 😄

#

It will still work regardless

tame cobalt
#

i'll try

#

thx btw

alpine river
#

No worries

tame cobalt
#

@alpine river I did what you said. but I get the following error on the host.

tame cobalt
#

@alpine riverI fixed it. I'm sorry to bother you.