Basic replication : Variable replicates incrorrectly

I am simply trying to replicate a variable in my game (Net Mode = Play As Listen Server).

My player has a variable that is called CurrentHealth wich is set to 100. When That player then presses 1 on the keyboard it chould subtract 10 from the CurrentHealth variable.
NOTE: The Current health variable is set to replicated

This is my setup:

When I press 1 on my keyboard (in the server window) to take damage the, the server says that it took 10 damage but the other two clients says that the server took 20 damage.

If I do the same thing in but as client 1 (top right window) the same problem occurs. The server says the client 1 took 10 damage but client 1 & 2 things that client 1 took 20 damage for some reason.

I want all of the players to see that the person that pressed 1 has taken 10 damage not 20. Any help would be appreciated!

Replication is when you SET a variable on the server only. It then eventually gets replicated to everyone.

You should start by making “CurrentHealth” RepNotify to you get a function which notify you when the variable has changed.

First you use the Input event that calls a RunOnServer event.
Secondly you SET the Current Value on the Server.
Thirdly you use the OnRep_CurrentHealth function to react to the health value changed.

1 Like

Adding to what @GarnerP57 posted…

Your “True and Managed Health” should be stored in PlayerState class. This value is what should be modified via Damage and Healing.

CurrentHealth (var in character class) should be a non-authoritative value you simply use for UI purposes.

1 Like

Thank you! This worked :smiley:

Here are some images in case any other lost soul like me have the same problem.


Also, here is the widget code wor my HP-Bar.

1 Like