Why isn't a int variable being updated with the server value after local change?

Hello, i declared a variable on my character like this:

UPROPERTY(Replicated)
int32 Test = 2;

and added the replication entry:

void AMyCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(AMyCharacter, Test);
}

When i press the F key, i set the value of Test to 3 only on the client, like this:

void AMyCharacter::OnPressedFKey()
{
	Test = 3;
}

On every tick i’m logging to the screen the value of Test, like this:

void AMyCharacter::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	LOG_SCREEN("%s %d      %d", *GetName(), (int32)Role, Test);
}

The server has the value 2 and the client has value 3 and doesn’t change back to 2, what am i doing wrong? Thank you.

My understanding of replication (which is pretty limited) is that setting a property to replicated ensures it will be replicated from the server to the client, not the other way around. So once you have set the value on the client, you need to send that back to the server which will then replicate the value to the other clients.

But that’s the thing, i dont want to send the value from the client to the server. I changed the value on the client and i want the server to force it’s value again. Using the previous example, on the server the value is 2 and i changed locally the client to 3 and i want it to revert to 2 again automatically, almost like a cheater would change it’s health to 999 and the server resets it to 100 because it’s the value he has.

The server only replicates to the clients when it knows the value has been changed. In your case the value is only being changed on the client so the server knows nothing about it.

If your client is cheating then as long as you still only apply the game rules on the server it shouldn’t matter. The client might cheat and show that health is 999, but the server will know that his health is really 100.

I was under the impression that each client has a copy of the values on the server and periodically (i’m not sure if it’s every tick) he compares the current value with that copy and if it’s different he replaces it