One variable for different players

If I have a FLOAT variable, let’s call it dollars.

This variable is created in the “Player State Class”.

Then I play with two players as “Play as listen server”.
Dollar is not replicated, just Instance Editiable.

Each player can now change the value of dollars for himself. How can each player also see what value the dollar variable has for the other player?

Hi, if it is not replicated, then he can’t since there is no client to client communication in UE (unless you want to make some crazy workaround to manually go through the server like client sends RPC to server, server sends RPC to other client, other client agains sends RPC with the value to the server and server sends RPC with that value to client). You need to make the variable replicated and change it only through the server (RPC with the new value to server). Then since it is replicated the server will automatically sent the changes to all clients.

Hi Analysierer

As @chrudimer suggested, ensure the variable is being set on the server and that it is being replicated. Each player can only access their own player state objects directly (as each player will have their own player state). If you want to access the player state from another player, you will need to use the “Players” array inside the Game State class.

Good luck.

Alex

Ok, i got it THX :slight_smile: