I’ll preface this by saying doing it this way, depending on the context, can be very dangerous. The server shouldn’t trust information coming from the client ever.
A function like you have above will work in conjunction with replicating the variable. The client can update it on their side and then send the RPC to the server which will update the variable on the server and trigger replication of the new value.