Doors not working properly with CFrame

I’m an absolute noob at CFrames and so far the only code I’ve done so far has been the combination of YouTube videos which didn’t quite explain CFrames very well to me with what I’m trying to accomplish.

Basically, I have a fridge and I’m trying to make the door and the handle of the door rotate at the same time so that I can create an opening animation with the door but it’s going horribly wrong but I don’t know how to fix it at all since I don’t understand CFrames much at all.

Here’s a video of what’s happening (not sure if I did it right or not, not showing up in preview):

The script that I’m using for that:

local Hinge = script.Parent.LeftHinge
local leftdebounce = false
local lefttoggle = false
script.Parent["Meshes/LeftDoor"].ClickDetector.MouseClick:Connect(function(Player)
	if leftdebounce then return end
	leftdebounce = true
	
	if not lefttoggle then
		for i = 270, 110, -1 do
			spawn(function()
				script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		leftdebounce = false
		lefttoggle = true
	else
		for i = 110, 270 do
			spawn(function()
				script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		leftdebounce = false
		lefttoggle = false
	end
end)

script.Parent["Meshes/LeftDoorHandle"].ClickDetector.MouseClick:Connect(function(Player)
	if leftdebounce then return end
	leftdebounce = true
	
	if not lefttoggle then
		for i = 270, 110, -1 do
			spawn(function()
				script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		leftdebounce = false
		lefttoggle = true
	else
		for i = 110, 270 do
			spawn(function()
				script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		leftdebounce = false
		lefttoggle = false
	end
end)

-- The right door is the same thing but renamed "RightDoor" and "RightDoorHandle"

Just a small note: I used a spawn() and a pcall() right after on another because the door and the handle were separate meshes so I thought I’d call one in a thread to run by itself while yielding for the other to catch up but I don’t think that did anything.

The main issue here is that the left door rotates backwards and the right door’s handles rotates too little to match the door’s rotation (or maybe the handle is rotating backwards)

Any articles on CFrames or just help in general is much needed, these YouTube videos really didn’t explain much in the technical process.

Thanks in advance.

Bad way to do it, you shouldn’t just rename it RightDoor and RightDoorHandle, you should change the CFrame values for the RightDoor and make them negative possibly, instead of the exact same values. They are both going different ways, so thats a possibility why it is doing that, because you did not value properly.

Whoops, forgot to mention that the right door and handle for loops are flipped around, so opening the left would be bigger going to smaller while the for loops on the right would be bigger to smaller (on the initial open)

Could you send the full script?

Mhm, it’s:

local Hinge = script.Parent.LeftHinge
local leftdebounce = false
local lefttoggle = false
script.Parent["Meshes/LeftDoor"].ClickDetector.MouseClick:Connect(function(Player)
	if leftdebounce then return end
	leftdebounce = true
	
	if not lefttoggle then
		for i = 270, 110, -1 do
			spawn(function()
				script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		leftdebounce = false
		lefttoggle = true
	else
		for i = 110, 270 do
			spawn(function()
				script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		leftdebounce = false
		lefttoggle = false
	end
end)

script.Parent["Meshes/LeftDoorHandle"].ClickDetector.MouseClick:Connect(function(Player)
	if leftdebounce then return end
	leftdebounce = true
	
	if not lefttoggle then
		for i = 270, 110, -1 do
			spawn(function()
				script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		leftdebounce = false
		lefttoggle = true
	else
		for i = 110, 270 do
			spawn(function()
				script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		leftdebounce = false
		lefttoggle = false
	end
end)

local RightHinge = script.Parent.RightHinge
local rightdebounce = false
local righttoggle = false
script.Parent["Meshes/RightDoor"].ClickDetector.MouseClick:Connect(function(Player)
	if rightdebounce then return end
	rightdebounce = true
	
	if not righttoggle then
		for i = 89, 259 do
			spawn(function()
				script.Parent["Meshes/RightDoorHandle"].CFrame = CFrame.new(RightHinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/RightDoor"].CFrame = CFrame.new(RightHinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		rightdebounce = false
		righttoggle = true
	else
		for i = 259, 89, -1 do
			spawn(function()
				script.Parent["Meshes/RightDoorHandle"].CFrame = CFrame.new(RightHinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/RightDoor"].CFrame = CFrame.new(RightHinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		rightdebounce = false
		righttoggle = false
	end
end)

script.Parent["Meshes/RightDoorHandle"].ClickDetector.MouseClick:Connect(function(Player)
	if rightdebounce then return end
	rightdebounce = true
	
	if not righttoggle then
		for i = 89, 259 do
			spawn(function()
				script.Parent["Meshes/RightDoorHandle"].CFrame = CFrame.new(RightHinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/RightDoor"].CFrame = CFrame.new(RightHinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		rightdebounce = false
		righttoggle = true
	else
		for i = 259, 89, -1 do
			spawn(function()
				script.Parent["Meshes/RightDoorHandle"].CFrame = CFrame.new(RightHinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			pcall(function()
				script.Parent["Meshes/RightDoor"].CFrame = CFrame.new(RightHinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
			end)
			wait()
		end
		rightdebounce = false
		righttoggle = false
	end
end)

I’m not so worried about the numbers in the for loops right now, those are just rough guesstimates which will be fine tuned after I first figure out why the doors and handles aren’t rotating properly.

I suggest you use Animations for this project. While CFrame might seem good, Animations are in my opinion easier and better on small levels, such as doors.

Animations for doors are much simpler. Here’s an animation door of mine you can pick apart. (it’s a bit old so dont make fun of me for bad coding lol) Animatated Door - Roblox

If you want to learn more about CFrames, I suggest you check out these two posts.

In the past I’ve used the TweenService in order to create animations on doors.

I’d suggest finding the end CFrame of parts of the door and then use the TweenService in order to smoothly transition to these new CFrame values