Struggling with PlayerState and Multiplayer

Sorry for the newbie question, but I’ve spent hours on YouTube and asking ChatGPT and I am still stuck.

I’ve boiled it down to basics just to make it simple. I want to click a button, and that player then gains +1 to their number. Then I just want the server announcing via a print string each players number.

Unfortunately, all that happens is the server adds to the servers number in the PlayerState, but the client also adds to the servers number, not to its own.

What am I missing?

Thanks!

You are getting the server’s player state with the Get Player State function call (index 0 is always the local player, so the listen-server when running anything on the server).

You probably meant to Get the Player State variable from the controller you were in, which is indeed correct… unfortunately right clicking and typing is not super helpful in this case…

Thanks for the help, but ironically this has now reversed the problem! Now all the number is increasing only for the client and not the server.

The problem seems to come from the fact I am using a widget to increase the number in the player state. When I simply bind keyboard keys to add and print the number, all works as expected. But when clicking on the widget UI button, it all breaks and goes weird.

Any idea how I am supposed to edit variables in the PlayerState through widgets?

Sounds like you don’t have a Is Local Controller test and branch before the code you posted. The server does have player controller’s for all clients, so that bind needs to happen only on local controllers, sounds like the server is re-binding this for all players.

i think more likely you’d want a SwitchHasAuthority and only run this code on server (not server RPC)

as this way you have the client tell the server what it did which leads to cheating