Need Guidelines for using Modbus Server for HMI Read/Write to the PLCNext Controller variables

We are looking for guidance about Modbus communication structure between the Controller variables and Modbus functions. We are designing a project with the 3152 Controller. The project needs to have the ability for Read(output) and On-demand Write(input) of variables with an external HMI. We intend on having a Modbus Server within the Controller for this interface. We setup a demonstration project and observed that the Server function appears to continuously overwrite the internal variables, even when no manual update is sent from the external HMI. Additional the project is intended to have several Modbus Client functions necessary to read data from other ethernet Modbus devices such as ETH BK rack, etc. Our first thought was to have Server and each Client function within a separate program. All programs sharing variable data via GDS. Also it seems that the Modbus Data Array variables are not directly transferable via GDS.
Any thoughts/use case experience will be most appreciated. Most importance is rsolving how to prevent overwrite of Controller variables when the HMI is not intending to write a changed value.

Hello.
You have to organize intermediate function block between array of modbus registers and finely named internal plc variables.
Function block have to detect change of plc variable or modbus register and provide sync between them.
It can be looks like (for bool variables).
R_HMI(CLK:= HMI);
F_HMI(CLK:= HMI);
R_PLC(CLK:= PLC);
F_PLC(CLK:= PLC);

IF PLC <> HMI
AND NOT R_PLC.Q AND NOT F_PLC.Q
AND NOT R_HMI.Q AND NOT F_HMI.Q
THEN
HMI := PLC;
END_IF;

IF R_HMI.Q AND NOT PLC THEN
PLC := 1;
END_IF;

IF F_HMI.Q AND PLC THEN
PLC := 0;
END_IF;

IF R_PLC.Q AND NOT HMI THEN
HMI := 1;
END_IF;

IF F_PLC.Q AND HMI THEN
HMI := 0;
END_IF;