Keep function from overlapping when denounce isn't possible

I am having an issue where if you were to spam open and close the door doe six seconds the statement after wait(6) is true and will cause the door to instantly close when you open it. Is there a way to cancel the function if the door is manually closed before the check occurs?

local Door = game.ReplicatedStorage.Door

local function Operate(door)
	if door.Open.Value == false then
		door.Open.Value = true
		if door:FindFirstChild("Left") then
			door.Left.Anchor.Motor.DesiredAngle = -1.5
		end
		if door:FindFirstChild("Right")then
			door.Right.Anchor.Motor.DesiredAngle = 1.5
		end
		door.Sound.Open:Play()
	else
		door.Open.Value = false
		if door:FindFirstChild("Left") then
			door.Left.Anchor.Motor.DesiredAngle = 0
		end
		if door:FindFirstChild("Right") then
			door.Right.Anchor.Motor.DesiredAngle = 0
		end
		door.Sound.Close:Play()
	end
	wait(6)
	if door.Open.Value == true then
		door.Open.Value = false
		if door:FindFirstChild("Left") then
			door.Left.Anchor.Motor.DesiredAngle = 0
		end
		if door:FindFirstChild("Right") then
			door.Right.Anchor.Motor.DesiredAngle = 0
		end
		door.Sound.Close:Play()
	end
end

Door.OnServerEvent:Connect(function(plr, door)
	Operate(door)
end)

Yep, use something that will never be the same again, for example tick() or elapsedTime() as a check of the thread its in:
e.g.

local localDoorId = elapsedTime()
globalDoorId = localDoorId

wait(6)
if globalDoorId ~= localDoorId then return end -- means another thread changed the value of globalDoorId, but the value of localDoorId will not change since it is local.
	if door.Open.Value == true then
		door.Open.Value = false
		if door:FindFirstChild("Left") then
			door.Left.Anchor.Motor.DesiredAngle = 0
		end
		if door:FindFirstChild("Right") then
			door.Right.Anchor.Motor.DesiredAngle = 0
		end
		door.Sound.Close:Play()
	end