'sensorState' does not name a type?

I’ve alr initialized the sensor’s state at the very beginning, but why can’t it work?

#include <Keypad.h>
#include <Servo.h>
Servo myservo;

#define Password_Length 4;

static const int spy = 0;
static const int analyst = 0;
static const int director = 0;

int sensor = 11;
int sensorState = 0;
int pos = 0;
int accessCode = 0;

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

char hexaKeys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},

{‘4’,‘5’,‘6’,‘B’},

{‘7’,‘8’,‘9’,‘C’},

{’*’,‘0’,’#’,‘D’}

};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

int value = 0;

char customKey = 0;

void setup() {
myservo.attach(10);
pinMode(sensor, INPUT);
setAccessCode(true);
Serial.begin(9600);
}

void loop(){
customKey = customKeypad.getKey();

if (customKey != NO_KEY) {
if ((customKey >= ‘0’) && (customKey<=‘9’)) {
value = value*10;
value = value + customKey - ‘0’;
}

if(customKey ==’#’) {
Serial.println(value);
value=0;
}

if (customKey == ‘*’ || customKey == ‘#’){
pos = 0;
setAccessCode(true);
}
////////set the keypad/////////

if (value == 700&&value == 314&&value ==161){
setAccessCode(true);
}
else {
setAccessCode(false);
}
}
}

void setAccessCode(int incorrect){
if (incorrect){
Serial.print(value);
myservo.write(0);
}
else{
myservo.write(90);
}

}

** sensorState = digitalRead(sensor);**

if (sensorState == HIGH) {
Serial.println(“Please input access code”);
}

else {
Serial.println();
}
}
}

Use the IDE autoformat function to indent your code. That can show misplaced and/or missing brackets. It looks like the loop() fuction may be closed before that line of code, causing the error.

That line and those following it are not contained in any function. Probably your {} are in a mess. Try Ctrl-T to get an idea of what's going on.

Steve