Can't close door after Key stops touching it

Hello, my last topic was about how to create a door about how to create a door that opened when you used a tool to touch it, I have now finished the script but I need to make the door go down after the key stops touching it.
I used Touched

The door is going up and down and when it says that it’s open, it’s actually closed.
I tried using BoolValues to let it know if it can open or not. Here is my script:

local waitTime = Instance.new("BoolValue")
local Ready = true
local closingVariable = true
     waitTime = false -- set to false so they can open the door.
      script.Parent.Touched:Connect(function(hit) -- when the key touches the door.
          if hit.Parent.Name == "Key" and waitTime == false then -- if the key touched it and the boolValue is false then it will go through.
        print("Door rising...") -- Prints that the part is rising as a debugger.
        waitTime = true -- Set to true so you can't open the door while it's rising.
     for currentCFrame = 5, 12.5, 0.05 do -- The Foor Loop to make the door rise.
    wait(0.025) -- The time it takes to rise, slow.
 script.Parent.CFrame = CFrame.new(0,currentCFrame,0) end
print("Door opened!")
Ready = false 
closingVariable = false
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent.Name == "Key" or Ready == false and closingVariable == false then
closingVariable = false
       for currentCFrame2 = 12.5,5, -0.05 do  
wait(0.025) -- Again the time to go down.
     script.Parent.CFrame = CFrame.new(0,currentCFrame2,0) end
print("Door can now be re-opened!") -- I used Print() to debug.
waitTime = false -- Set to false and people can open the door again.
end end) end end)

Why does this happens?

Use TweenService to make the door rise/fall. (A tip)

If I had to visualize the situation, it’s because both Touch and TouchEnded events are playing at the same time.

The TouchEnded in your code can still play afterwards multiple times, if you Touched the door atleast once. That’s how connections work. The TouchEnded stacks, because the connection is made everytime Touched event plays. You need to format your code a different way.

To help: (Can’t test this for myself)

local DoorOpen = false
local Door = -- that door

Door.Touched:Connect(function(hit)
   if hit.Parent.Name == "Key" and DoorOpen == false then
       DoorOpen = true
       -- TweenService the door going down
       -- TweenBase.Completed:Wait() -- It waits until the door met its position goal.
           Door.TouchEnded:Wait() -- Repeats wait until something isn't touching anymore.
       -- TweenService the door going up
       -- TweenBase.Completed:Wait()
           DoorOpen = false
   end
end)

I was testing some code I found in another topic, sorry for the late reply. I will make sure to try that.
Edit: Your script didn’t work.

Edit: I got it working with another script, thank you for helping me though.