Changing a variable on the GameState from a client Player Controller

Hello, I am developing a multiplayer racing game. Take a look at the attached screenshots.

I am trying to set a “Race Ended?” Boolean variable on the GameState from the Player Controller that completes the race first. That way, when a connected client completes the race, the “Set Race Ended” RPC (that runs on server) marks the “Race Ended?” bool as true, and other connected clients cannot get the “Winner” widget blueprint added to their screens.

In the attached screenshots, if the server’s Player Controller runs through this code, the “Race Ended?” boolean is marked as true, and all other connected clients print the “Race Winner Already Determined” when they complete the race.

The issue I’m having is when a connected client finishes the race, or in other words, casts to BP_GS_Gameplay (gamestate). When they do this, they run through False on the branch like normal, but the “Race Ended?” bool is not replicated to all the clients, so the next Player Controller to cross the finish line also receives the “Winner” widget blueprint notification.

This continues to happen until the server’s Player Controller casts to the GameState and marks the variable.

I feel like I am completely misunderstanding how replication works in this scenario. Are client Player Controllers able to call RPCs on the GameState and trigger events that can change variables on the GameState (that can be replicated down to all of the clients)?

A basic summary:

  1. In my Player Controllers (could be client or server) I am casting to the GameState
  2. I am calling an RPC (that runs on server) on the GameState
  3. I am marking the bool “Race Ended” as true
  4. The next time someone runs through this code, they should go through the TRUE branch because “Race Ended?” is marked for replication on the GameState
    Problem: this is only happening if the server triggers the RPC on the GameState, even though the RPC is set to Run On Server.

Any help would be greatly appreciated.


image1 (1)