Door issue with touch

Hello

So i’ve been trying to make a door that opens when you touch a “Detector”, now there’s a problem, if you quickly run in and out of the detector part, the door remains open until you enter and leave again, is there any way to fix this? Maybe something that constantly checks if something is touching? I don’t know, please help.

Also sometimes it just stays open when you leave the detector area.

local TweenService = game:GetService("TweenService")
local door1 = script.Parent.door1.doorObject
local door2 = script.Parent.door2.doorObject

local lockValue = game.Workspace.CoreSystems.Values.lockdownValue
local blink = game.Workspace.CoreSystems.Values.alarmSync
----------------------------------------------------
local closedpos1 = Vector3.new(door1.Position.X, door1.Position.Y, door1.Position.Z)
local openpos1 = Vector3.new(door1.Position.X, door1.Position.Y, door1.Position.Z - 3)

local closedpos2 = Vector3.new(door2.Position.X, door2.Position.Y, door2.Position.Z)
local openpos2 = Vector3.new(door2.Position.X, door2.Position.Y, door2.Position.Z + 3)

local movetime = 1 -- Movement speed in seconds.



--local opensfx = script.Parent.doorObject.lockdown_open
--local closesfx = script.Parent.doorObject.lockdown_close
local doorstatus = "opened"
----------------------------------------------------
local CloseProperties1 = {
	Position = closedpos1
}

local OpenProperties1 = {
	Position = openpos1
}

local CloseProperties2 = {
	Position = closedpos2
}

local OpenProperties2 = {
	Position = openpos2
}



local TweenInfoo = TweenInfo.new(movetime,Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local TweenOpen1 = TweenService:Create(door1, TweenInfoo, OpenProperties1)
local TweenClose1 = TweenService:Create(door1, TweenInfoo, CloseProperties1)

local TweenOpen2 = TweenService:Create(door2, TweenInfoo, OpenProperties2)
local TweenClose2 = TweenService:Create(door2, TweenInfoo, CloseProperties2)

----------------------------------------------------






door1.Position = closedpos1



local detector = script.Parent.detector

local function onPartTouched(otherPart)
	local partParent = otherPart.Parent
	
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		doorstatus = "moving"
		TweenOpen1:Play()
		TweenOpen2:Play()
		--opensfx:Play()
		wait(1.1)
		doorstatus = "opened"
		end
	end


local function OnPartTouchEnded(otherPart)
	local partParent = otherPart.Parent
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	
	if humanoid then
		doorstatus = "moving"
		TweenClose1:Play()
		TweenClose2:Play()
		--closesfx:Play()
		wait(1.1)
			doorstatus = "closed"
	end
	end


detector.Touched:Connect(onPartTouched)
detector.TouchEnded:Connect(OnPartTouchEnded)