How to change a Variable in the PlayerState

Hello!
I’m trying to change a Variable on the PlayerState. I change the Variable by clicking on a Widget Button (See picture). But if I want to read the variable on the Server - it is still 0.
I don’t understand why, because I thought the playerstates are always available on all machines. Can you tell me why the variable is not changing its value?
Thanks for your help!

Hello there! The reason it’s still 0 in the server is because you are changing it from the client. The client does not send variable changes to the server, only the server to the client(s). So what you want to do is make an event with “Called on server” replication, preferably in your player state, and make an Integer as argument. There change the variable of the integer you want, taken from the argument. Then from your widget call this event you created and pass the integer you want.Then the server will change the value and replicate that automatically to your client aswell.

2 Likes

Thank you very much for this helpful, clear answer! You’re absolutly right and your solution runs pefectly :). There is one thing I don’t unterstand:

. So it would be possible to do this directly on the WidgetBP, but how could the Server find the correct PlayState?

Glad to hear it worked. Well widgets run on client only so unfortunately making an event with replication inside the widget would have no effect. I usually run these kind of things in the player state :slight_smile: