CFrame Door Error

Problem:
I am currently working on setting up a CFrame sliding door. However, I have two different parts (Door, Door2) which I would like to move with one single button. When I press the button, however, the parts both do move to the side as wanted, but Door2 “teleports” to the position of Door. No errors occur. How can I make it so both of these parts move, but in their individual positions?

Here is the script:
image

Here is the workspace:
image

:pray:Thank you for any help you can provide.

The thing that could be causing this problem is, when you are setting the CFrame of the door2 you are using door as the CFrame to go off of, instead of the door2, which is probably making it teleport to that spot.

2 Likes

You could use tweenservice instead of a loop. Tweenservice will change the CFrame of the door to the position, instead of just teleporting the part to your set CFrame, where you could also set the amount of time from position A to position B.

1 Like

Is there any additional information you can give out? The answer would most likely depend on how you’re wanting the door to move around. (Eg. In opposite directions, the same direction in a layered-type way, etc.)

This isn’t an error, this is a problem with your implementation. There’s literally only one correction you have to make: the fact that you’re using the CFrame of door(1) for door2.

-- Use local variables and prevent writing repetitive statements
local doorGroup = script.Parent.Parent
local door = doorGroup.door
local door2 = doorGroup.door2

local function onClicked()
    for i = 1, 70 do
        door.CFrame = door.CFrame * CFrame.new(0, 0, 0.1)
        -- This is where your issue was: using door.CFrame over door2.CFrame
        door2.CFrame = door2.CFrame * CFrame.new(0, 0, 0.1)
        wait()
    end
    wait(3)
    for i = 1, 70 do
        door.CFrame = door.CFrame * CFrame.new(0, 0, -0.1)
        -- This is where your issue was (again)
        door2.CFrame = door2.CFrame * CFrame.new(0, -0, 0.1)
        wait()
    end
end

-- Use PascalCase Connect; lowercase connect is deprecated
script.Parent.ClickDetector.MouseClick:Connect(onClicked)

As a little addendum, I don’t typically recommend CFraming doors in this fashion. I created a tutorial on model tweening which allows you to smoothly move multiple-part doors and other kinds of assemblies. You can read up on that here:

2 Likes

The issue is you’re doing

door.CFrame = door.CFrameCFrame.new(0, 0, 0.1)
door2.CFrame = door.CFrame
CFrame.new(0, 0, 0.1)

—correct code—
door.CFrame = door.CFrameCFrame.new(0, 0, 0.1)
door2.CFrame = door2.CFrame
CFrame.new(0, 0, 0.1)

2 Likes