So I have an event tick which removes float values (hunger, thirst). If they go low, it starts to remove my hp.
I run a multiplayer setup. And If one of the players gets to 0HP. They all get hello print string… Why? Why don’t only the player with 0hp get it? Is it a replicated event?
Thats because character object exists in both clients so they tick on both, in otherwords you running same code on both clients and server too, so it’s not really replication. You need to check if you run on Server:
Other option is to run this on PlayerController which is exist only on server and client that owns it. But any stats should be processed on server for security
That doesn’t really answer my question. If only one players health is 0, why do all players get the message?
He is right though. The event runs on every character not just your own. Use IsLocallyControlled and only call it if true.
Remember that every Player exists on every machine in the network, and unless the players’ code branches on whether the machine is a network authority or server, it then all copies of that player on all machines will run the same code, including that print node.
I still don’t get it…
How can it be?
How can all players die if only 1 has 0 health
The others should die only when theyr health goes to 0…
The condition is, if health<=0, but other are false… Why they all get server:hello client1:hello If it should only say server:hello?
IsLocally does no help. The death screen pops up on both players. Even tho one is still alive…
You need to show more of how and where you are calling things to help us help you. You need a solid understanding of where Actors live (Server,Client 1, Client 2 etc.) and how Ownership and Pawn possession (Is Controlled) works in order to solve things like this.
I don’t think every player is going to die (but you can test that if you want). It’s just that Player Controllers exist on every machine (although they are not CONTROLLED from there). Also every Pawn exists on every machine because otherwise there’s nobody to shoot at in a networked game. As such, their code is going to run on all machines (except where you branch on remote/authority or isServer).
So let’s say you have 8 players, one on each of 8 computers.
Computer 1 has a controller and pawn running code for player 5,
Computer 2 has a controller and pawn running code for player 5,
Computer 3 has a controller and pawn running code for player 5,
And so on through Computer 8.
Player 5’s health drops to 0. This happens on all the Computers. So the code for player 5 runs on all the computers.
Print nodes display a message on the computer the code ran on, regardless of which Actor runs the print node, so even if player 2 didn’t run the print node, player 5 has a controller and pawn running that code on player 2’s computer, and player 5 on player 2’s computer still has to run code in order to exist on player 2’s computer. So player 2 gets the print message, along with everyone else for whom player 5 exists (which is everyone who is in the same game session).
So if player 5 dies, then player 5 will execute the code to make player 5 die on computers 1,2,3,4,5,6,7 and 8. That way player 5 dies on all of the computers, which is usually how you want it to work. You don’t want it to only execute the dying code for player 5 on player 5’s computer, or else he will still be alive on all the other computers.
So I think if you change the Print node to the code to make him die, then you’ll get the results you want.
So I found my mistake. The screenshot was fine. The problem was HP replication. I did not replicate restore health. So server never knew that player has more hp. So regardless of what client’s hp was, server had the old value. Thanks everyone for help.