Doors start acting weird if you spam click it

Hello, so My door system works basically with motors, but i’ve been having a trouble,because if you spam the doors it starts acting REALLY weird, I think it’s because the delay(8,function() that checks if door’s open and close it

for i,v in ipairs(workspace.Map.Chunk1.Doors:GetChildren()) do
	doordebounce[v] = false
	if v.Name == "SingleDoor" then
	v.Moving.ClickDetector.MouseClick:Connect(function(Player)
		local Position = v.Moving.Door.CFrame:PointToObjectSpace(Player.Character.HumanoidRootPart.Position)
	
		if v.Open.Value == false and  doordebounce[v] == false then
			v.Open.Value = true
			doordebounce[v] = true
			v.Important["Door Opening"]:Play()
			if Position.Z < 0 then
				
					v.Moving.Primary.Motor.DesiredAngle = 1.4		
				elseif Position.Z > 1 then
				v.Moving.Primary.Motor.DesiredAngle = -1.4
			end
		elseif v.Open.Value == true and  doordebounce[v] == false  then
				v.Moving.Primary.Motor.DesiredAngle = 0
				v.Open.Value = false
			end
			delay(8, function()
				if v.Open.Value == true then
					v.Open.Value = false
					v.Moving.Primary.Motor.DesiredAngle = 0
					doordebounce[v] = false
					end
				end)
					wait(1)
					doordebounce[v] = false
		end)
			elseif v.Name == "DoubleDoor" then
					v.Moving.ClickDetector.MouseClick:Connect(function(Player)
		local Position = v.Moving.Door.CFrame:PointToObjectSpace(Player.Character.HumanoidRootPart.Position)
	
		if v.Open.Value == false and doordebounce[v] == false then
			v.Open.Value = true
			if Position.Z < 1 then
				
					v.Moving.Primary.Motor.DesiredAngle = 1.4		
					v.Moving.Primary1.Motor.DesiredAngle = -1.4	
				elseif Position.Z  > 1 then

					v.Moving.Primary1.Motor.DesiredAngle = 1.4	
				v.Moving.Primary.Motor.DesiredAngle = -1.4
			end
		elseif v.Open.Value == true and doordebounce[v] then
				v.Moving.Primary.Motor.DesiredAngle = 0
				v.Moving.Primary1.Motor.DesiredAngle = 0
				v.Open.Value = false
			
			end
				delay(8, function()
				if v.Open.Value == true then
					v.Open.Value = false
				v.Moving.Primary.Motor.DesiredAngle = 0	
					v.Moving.Primary1.Motor.DesiredAngle = 0
					doordebounce[v] = false
					end
				end)
					wait(1)
					doordebounce[v] = false
		end)
			end
end

https://gyazo.com/3a498364c04d60407fcd8adf662bb761

You can disable a clickdetector by using MaxActivationDistance. Try making it so that when the animation for the door is happening, set the MaxActivationDistance to 0, and when it’s done, set it to the default value of the clickdetector (Being 32 by default)

2 Likes