Motor6d Plugin Help

Im trying to animate a plane door but it isn’t working. I tried watching two youtube tutorials but it didn’t work. Can you guys try to fix my script?

open = false
local motor = script.Parent.Parent.Door2.Motor

script.Parent:WaitForChild('ClickDetector').MouseClick:connect(function()
	if open == false then
		script.Parent.ClickDetector.MaxActivationDistance = 0
for i = 1,5 do	
	motor.C1 = motor.C1 * CFrame.new(0,0,0.09)
	wait(0.001)
end	
	for i = 1, 35 do
		motor.C1 = motor.C1 * CFrame.new(0.09, 0 , 0)
		wait(0.001)
	end
		open = true
		script.Parent.ClickDetector.MaxActivationDistance = 10
		
	elseif open == true then
		script.Parent.ClickDetector.MaxActivationDistance = 0
		for i = 1,35 do 
			motor.C1 = motor.C1 * CFrame.new(-0.09, 0, 0)
			wait(0.001)
		end
		for i = 1, 5 do
			motor.C1 = motor.C1 * CFrame.new(0,0,-0.09)
		end
		open = false 
		script.Parent.ClickDetector.MaxActivationDistance = 10		
end

	
end)

Edit it for me if you see any mistakes

To me it seems like you are really overcomplicating this! You could make this much simpler by putting a physical motor into your model (I would recommend using this plugin: https://www.roblox.com/library/174430395/Motor6D-Maker) and then using a script like such:

local motor = script.parent.Motor
local CD = script.Parent.ClickDetector
local Open = false

motor.MaxVelocity = 0.02

CD.MouseClick:Connect(function()
if Open == true then
motor.DesiredAngle = 1.5
Open = false
else
motor.DesiredAngle = 0
Open = true
end
end)

I believe there are a few tutorials on youtube as to how to use the plugin but once you get the hang of it its very easy to use!