It sounds like you what you are looking for is Replication.
You are achieving replication through RPCs, which also works. If you want to clean up the code a little it’s simpler to set the variables to be replicated.
- Add UPROPERTY(Replicated) above your variable that you want to be replicated.
- Implement GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
- Add DOREPLIFETIME(AReplicatedActor, bIsSprinting); in GetLifetimeReplicatedProps
In order for a value to be replicated, it needs to be modified on the server and is then replicated to all clients.
UPROPERTY(ReplicatedUsing=OnRep_Flag) also exists, which will call OnRep_Flag() everytime the variable is replicated.