'val' does not name a type

keep getting error code and can not work it out, I am trying to use 2 Arduino Compatible PIR Motion Detector Module's to light up LED's and the eventually swap the LED's for a scoring board with an LCD screen, if you know which library also would be appreciated

here is my code

int led1 = 13; // the pin that the LED is atteched to
int led2 = 14; // the pin LED2 is attatched to
int sensor = 2; // the pin that the sensor is atteched to
int sensor2 = 4; // the pin sensor 2 is attatched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)
int val2 = 2; // variable to store the sensor status (value) for sensor2

void setup() {
pinMode(led1, OUTPUT); // initalize LED as an output
pinMode(led2, OUTPUT); // initalize LED2 as an output
pinMode(sensor, INPUT); // initialize sensor as an input
pinMode(sensor2, INPUT); // initialize sensor2 as an input
Serial.begin(9600); // initialize serial
}

void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(led1, HIGH); // turn LED ON
delay(100); // delay 100 milliseconds

if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(led1, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds

if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
}

val2 = digitalRead(sensor2); // read sensor2 value
if (val2 == HIGH) { // check if the sensor is HIGH
digitalWrite(led2, HIGH); // turn LED2 ON
delay(100); // delay 100 milliseconds

if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(led2, LOW); // turn LED2 OFF
delay(200); // delay 200 milliseconds

if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
}

here is my error message:

Arduino: 1.8.12 (Mac OS X), Board: "Arduino Uno"

sketch_jun03a:40:1: error: 'val2' does not name a type
val2 = digitalRead(sensor2); // read sensor2 value
^~~~
sketch_jun03a:41:3: error: expected unqualified-id before 'if'
if (val2 == HIGH) { // check if the sensor is HIGH
^~
sketch_jun03a:50:3: error: expected unqualified-id before 'else'
else {
^~~~
sketch_jun03a:59:1: error: expected declaration before '}' token
}
^
exit status 1
'val2' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Any help appreciated

Sure. Press ctrl-T to auto format the code and you will see the misplaced bracket. The statement that triggered the error is not inside any code block.

Please use code tags next time you post code.

Removed a " } " at line 37, compiles now:

int led1 = 13;                // the pin that the LED is atteched to
int led2 = 14;               // the pin LED2 is attatched to
int sensor = 2;              // the pin that the sensor is atteched to
int sensor2 = 4;             // the pin sensor 2 is attatched to
int state = LOW;             // by default, no motion detected
int val = 0;                 // variable to store the sensor status (value)
int val2 = 2;                // variable to store the sensor status (value) for sensor2

void setup() {
 pinMode(led1, OUTPUT);      // initalize LED as an output
 pinMode(led2, OUTPUT);     // initalize LED2 as an output
 pinMode(sensor, INPUT);    // initialize sensor as an input
 pinMode(sensor2, INPUT);    // initialize sensor2 as an input
 Serial.begin(9600);        // initialize serial
}

void loop(){
 val = digitalRead(sensor);   // read sensor value
 if (val == HIGH) {           // check if the sensor is HIGH
   digitalWrite(led1, HIGH);   // turn LED ON
   delay(100);                // delay 100 milliseconds
   
   if (state == LOW) {
     Serial.println("Motion detected!");
     state = HIGH;       // update variable state to HIGH
   }
 }
 else {
     digitalWrite(led1, LOW); // turn LED OFF
     delay(200);             // delay 200 milliseconds
     
     if (state == HIGH){
       Serial.println("Motion stopped!");
       state = LOW;       // update variable state to LOW
   }
 }
//} removed <<<<<<<<<<<<<<<<<


val2 = digitalRead(sensor2);   // read sensor2 value
 if (val2 == HIGH) {           // check if the sensor is HIGH
   digitalWrite(led2, HIGH);   // turn LED2 ON
   delay(100);                // delay 100 milliseconds
   
   if (state == LOW) {
     Serial.println("Motion detected!");
     state = HIGH;       // update variable state to HIGH
   }
 }
 else {
     digitalWrite(led2, LOW); // turn LED2 OFF
     delay(200);             // delay 200 milliseconds
     
     if (state == HIGH){
       Serial.println("Motion stopped!");
       state = LOW;       // update variable state to LOW
   }
 }
}

thank you very much

Karma bumped for providing the solution.