Double rotating door?

Hi, I currently have a script of a door that moves outwards linearly, but I would like to make the door rotate 90 degrees instead. (Like opening a normal double door) How can I tweak this script to achieve this?

local DoorOpen = game.ReplicatedStorage.DoorOpen

open = false

door1 = game.Workspace:WaitForChild("Door1")

door2 = game.Workspace:WaitForChild("Door2")

local TweenService = game:GetService("TweenService")

local part = script.Parent

 

local tweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

 

local Door1Open = {CFrame = door1.CFrame + door1.CFrame.lookVector * 4}

local Door2Open = {CFrame = door2.CFrame + door2.CFrame.lookVector * 4}

local Door1Close = {CFrame = door1.CFrame }

local Door2Close = {CFrame = door2.CFrame }

 

local Open1 = TweenService:Create(door1,tweenInfo,Door1Open)

local Open2 = TweenService:Create(door2,tweenInfo,Door2Open)

local Close1 = TweenService:Create(door1,tweenInfo,Door1Close)

local Close2 = TweenService:Create(door2,tweenInfo,Door2Close)

DoorOpen.OnClientEvent:Connect(function()
	wait(11)
	game.Workspace.ElevatorOpen:Play()
 if open == false then
	Open1:Play()
	Open2:Play()
	wait(2)
	open = true
 else
	Close1:Play()
	Close2:Play()
	wait(2)
	open = false
 end
end)
```lua
1 Like

Angled CFrame.

CFrame = door1.CFrame * CFrame.Angles(INPUT_HERE)

INPUT_HERE represents a X, Y and Z rotation in radians. You can use math.rad to turn a degree into a radian measure so that you don’t have to do that conversion yourself.

-- Turn 180 degrees into radian measure
math.rad(180) --> 3.14...

You will require a pivoting point. Rotating a CFrame like this will also rotate it by the center of the part, so the door would rotate as well. You can either add a CFrame outward or use a pivot part that will be rotated at its center while the door swivels around with said pivot part.

2 Likes