How to update a variable on a NPC?

Options
So, I have a health variable on my NPC that I want to pass throug all my players. The problem is that the NPC is writing data and reading data on both clients, and when it gets a hit, on one client it writes that its 80 HP and on the other 100 HP, and this causes the health to never go down. How can I fix this?

Comments

  • Hi @Wolf1806,

    for synchronizing health the best way might be to use Remote Procedure Calls. In your case, one client (e.g. the MasterClient) can send the RPC, which gets called on all clients and processes a certain function. In this function each client can for example reduce the health value of the object or apply a certain value. To see how RPCs work, I recommend you taking a look at the RPCs and RaiseEvent documentation page.
  • I concur. We have had good luck with HP using streamed syncing via "OnPhotonSerializeView" but then for enemies we have also used RPC calls as Christian_Simon said. We've had good luck with both options to be honest. Streamed syncing is way simpler and easier in my opinion but its not as responsible.