Announcement

Collapse
No announcement yet.

How to change a Variable in the PlayerState

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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!Click image for larger version

Name:	5.png
Views:	1
Size:	172.8 KB
ID:	1224962

    #2
    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.

    Comment


      #3
      Originally posted by DjSt3rios View Post
      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.
      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:
      preferably in your player state
      . So it would be possible to do this directly on the WidgetBP, but how could the Server find the correct PlayState?

      Comment


        #4
        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

        Comment

        Working...
        X