How to substituite delay function in a system?

Hi everyone! I'm not a big expert of coding.
I'm developing a code which allows me to record force applied in a bag ( through a load cell the system is able to detect the force applied on it ), what I want design is that the system recording in real-time always ( that already works ) and when I hit the bag with a punch, I would that system print only the maximum value in only one string of text ( that almost works ). Furthermore, I want to substitute the delay function with milliss, but as I said I'm not an expert and I don't know how to use millis in a system that start, run always and it needs just a sort of countdown in some part of code where it request to be stopped for 2 seconds and then restart again to work and start from that point it left.


#include<Keyboard.h>
#include <HX711.h>
#define calibration_factor   -9850
#define LOADCELL_DOUT_PIN 3
#define LOADCELL_SCK_PIN 2

// Dichiarazione delle variabili
HX711 scale;
float measurement;
float startpoint;
float highMeasurement;
float sogliafissa;
float stopsogliafissa;
bool startedRecording;


void setup() {

//Inizializzazione Board Arduino 
Serial.begin(9600);
Keyboard.begin();
while(!Serial);

//Inizializzazione dei PIN di lavoro cella di carico
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(calibration_factor);
scale.tare();

//Inizializzazione condizioni di lavoro cella di carico
measurement = 0;
startpoint = 1;
sogliafissa = 1;
stopsogliafissa = -1;
highMeasurement = 0;
startedRecording = false;
Serial.println("Waiting for Highest Measurement...");
}

void loop() {

//Attivazione acquisizione dati da cella di carico
measurement = scale.get_units();

  if (measurement < startpoint){
      startedRecording = true;
      highMeasurement = measurement;
  }

  else if (measurement > startpoint){
           startpoint = measurement;
           highMeasurement = startpoint;
           delay(300);
           startpoint = sogliafissa;
           
           if (startedRecording){
        
               finish();             
     }        
   }
 }
   
//Stampare potenza rilevata sul Serial Monitor
void finish(){

     Serial.print("Highest Measurement:  ");
     Serial.print(highMeasurement, 1);
     Serial.print("Kg");
     Serial.println();
  }  

This is the code that I wrote, using the delay works but I know it might create problem when the program is run for a long time.
Do you have suggestion about how to improve my code ?

Study this excellent tutorial: https://www.baldengineer.com/blink-without-delay-explained.html

Post again if you still have questions.

using the delay works but I know it might create problem when the program is run for a long time.

I doubt there will be a problem. In some cases use of delay() is fine.

It will also work if you simply remove the delay().

Do you have another program where a delay really is required?

I know that it works even without delay but I put there because without it I receive more than one string of text, with delay it's more accurate

If you know a minimum sample time then you can use millis() to wait until the interval has elapsed, before calling finish().

I saw that millis() works using the timer activated when the Arduino is started, but I don't know when someone hit the bag, for that reason I think I need an function that start the timer when it arrives at that point, start the countdown and then exit from the countdown and continue the normal code.

You know that:

At that time remember the startTime and continue until
millis()-startTime > interval