Servo Motor and Magnetic Sensor Coding Assistance.

Hello everyone!
I have undergone a seemingly simple project, and have hit a snag. Currently, this code,

#include <Servo.h>

const int red = 13;
const int Switch = 7;
const int servo = 8;
Servo Serv1;
int angle = 0;
int maxi = 95;
void setup() 
    {
        pinMode(red, OUTPUT);
        pinMode(Switch, INPUT_PULLUP);
        Serv1.attach(servo);   
    }

void loop() 
    {
        int SwitchState = digitalRead(Switch);
        
        if (SwitchState == HIGH) 
        {
          digitalWrite(red, HIGH);
          Serv1.write(38);
          delay(250);
        }
        else
        {
            digitalWrite(red, LOW);
            Serv1.write(90);
            delay(15);
        }
    }

has been rotating a servo from 90 to 38 when the magnetic sensor becomes separated. The servo rotating to 38, presses a space bar to play and pause a video. Currently the code will pause the video when the magnet loses contact, although I would like it to play the video once the magnet has lost contact and regained contact.
I feel as if this should be as simple as the rest of the code, but I have had 0 luck. I would really appreciate some help.
Thank you!

Use a "falling edge trigger" such as:

byte pastState = 0;
byte currentState = 0;

loop()
{
   pastState = currentState;
   
   if(digitalRead(pin))
   {
      currentState = 1;
   {
   else
   {
      currentState = 0;
   }
   
   if((currentState == 0) && (pastState == 1))
   {
      servo.write(38);
   }
   else
   {
      servo.write(90);
   }
}

I really appreciate the help! I put in that code, the way that I thought it would work. Not quite there. I must have done it wrong. Currently, the servo is set off only after the magnet is disconnected and then connected.

#include <Servo.h>

const int red = 13;
const int Switch = 7;
const int servo = 8;
Servo Serv1;
int angle = 0;
int maxi = 95;
byte pastState = 0;
byte currentState = 0;
void setup() 
    {
        pinMode(red, OUTPUT);
        pinMode(Switch, INPUT_PULLUP);
        Serv1.attach(servo);   
    }

void loop() 
    {
      pastState  = currentState;
        int SwitchState = digitalRead(Switch);
        
        if (SwitchState == HIGH) 
        {
          currentState = 1;

        }
        else
        {
          currentState = 0;

        }
        if((currentState == 0) && (pastState == 1))
        {
          digitalWrite(red, HIGH);
          Serv1.write(38);
          delay(250);
        }
        else
        {
             digitalWrite(red, LOW);
            Serv1.write(90);
            delay(15);
        }
        
    }

jonner13: I must have done it wrong. Currently, the servo is set off only after the magnet is disconnected and then connected.

But isn't that what you wanted it to do?

jonner13: I would like it to play the video once the magnet has lost contact and regained contact.