Its suppose to rotate like a door [Realistically]

Script:

script.Parent.PrimaryPart = script.Parent.Main
local Main = script.Parent:GetPrimaryPartCFrame()
local part = script.Parent.Main

function onClicked()
	if script.Parent.Open.Value == 0 then 
		for i = 0,1.5,0.1 do 
			wait(0.1)
			part.CFrame = script.Parent:SetPrimaryPartCFrame(script.Parent.Main.CFrame)*CFrame.fromEulerAnglesXYZ(0,-0.1,0)*CFrame.new(0.01,0,-0.25)
		end

main focus is when im trying to rotate it, The output says that

"Workspace.Door.Script:9: bad argument #1 to '?' (CFrame expected, got nil)"

Note: This is only part of the script.

Rest of script:

script.Parent.PrimaryPart = script.Parent.Main
local Main = script.Parent:GetPrimaryPartCFrame()
local part = script.Parent.Main
local x, y, z = part.CFrame:toEulerAnglesXYZ()
local rotation = CFrame.Angles(x, y, z)

function onClicked()
	if script.Parent.Open.Value == 0 then 
		for i = 0,1.5,0.1 do 
			wait(0.1)
			part.CFrame = script.Parent:SetPrimaryPartCFrame(script.Parent.Main.CFrame)*CFrame.fromEulerAnglesXYZ(0,-0.1,0)*CFrame.new(0.01,0,-0.25)
		end
			Main.CFrame = Main*CFrame.fromEulerAnglesXYZ(0,-math.pi/2,0)*CFrame.new(-2.5,0,-2.5)
			script.Parent.Open.Value = 0
		end
if script.Parent.Open.Value == 1 then
	for i = 0,1.5,0.1 do
		wait(0.1)
		Main.CFrame = Main.CFrame*CFrame.fromEulerAnglesXYZ(0,0.1,0)*CFrame.new(-0.01,0,0.25)
	end
		Main.CFrame = Main*CFrame.fromEulerAnglesXYZ(0,math.pi/2,0)*CFrame.new(-2.5,0,2.5)
		script.Parent.Open.Value = 1
	end
end
									
script.Parent.ClickDetector.MouseClick:connect(onClicked)