Tweened door is not closing properly

  1. What do you want to achieve? Keep it simple and clear!
    Tweened door that work properly

  2. What is the issue? Include screenshots / videos if possible!
    The door is not closing properly (As you can see from the video below)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I know that the problem have something to do with the CFrame tweening stuff and I’m not very good at it. I tired changing the numbers but still won’t work

local ClickDetect = script.Parent
local TweenService = game:GetService("TweenService")

local Door = script.Parent.Parent.Parent.Door
local DoorRoot = script.Parent.Parent.Parent.PrimaryPart
local Open = script.Parent.Parent.Parent.Open

local Info = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)

local DoorOpening = TweenService:Create(DoorRoot, Info, {CFrame = DoorRoot.CFrame * CFrame.Angles(0, math.rad(-90), 0)})
local DoorClosing = TweenService:Create(DoorRoot, Info, {CFrame = DoorRoot.CFrame * CFrame.Angles(0, math.rad(45), 0)})

local function OnClick()
	if Open.Value == false then
		DoorOpening:Play()
		Open.Value = true
	else
		DoorClosing:Play()
		Open.Value = false
	end
end

ClickDetect.MouseClick:Connect(OnClick)

--Changing

Open.Changed:Connect(function()
	if Open.Value == false then
		script.Parent.Parent.BillboardGui.TextLabel.Text = "Click to open"
	else
		script.Parent.Parent.BillboardGui.TextLabel.Text = "Click to close"
	end
end)

--Hovering

ClickDetect.MouseHoverEnter:Connect(function()
	script.Parent.Parent.BillboardGui.Enabled = true
end)

ClickDetect.MouseHoverLeave:Connect(function()
	script.Parent.Parent.BillboardGui.Enabled = false

end)

1 Like

Why are you doing this? Wouldn’t it be logical that the correct angle of the door in its original position would simply be 0 degrees, why 45 degrees?

local ClickDetect = script.Parent
local TweenService = game:GetService("TweenService")

local Door = script.Parent.Parent.Parent.Door
local DoorRoot = script.Parent.Parent.Parent.PrimaryPart
local Open = script.Parent.Parent.Parent.Open

local Info = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)

local DoorOpening = TweenService:Create(DoorRoot, Info, {CFrame = DoorRoot.CFrame * CFrame.Angles(0, math.rad(-90), 0)})
local DoorClosing = TweenService:Create(DoorRoot, Info, {CFrame = DoorRoot.CFrame * CFrame.Angles(0, 0, 0)})

local function OnClick()
	if Open.Value == false then
		DoorOpening:Play()
		Open.Value = true
	else
		DoorClosing:Play()
		Open.Value = false
	end
end

ClickDetect.MouseClick:Connect(OnClick)

--Changing

Open.Changed:Connect(function()
	if Open.Value == false then
		script.Parent.Parent.BillboardGui.TextLabel.Text = "Click to open"
	else
		script.Parent.Parent.BillboardGui.TextLabel.Text = "Click to close"
	end
end)

--Hovering

ClickDetect.MouseHoverEnter:Connect(function()
	script.Parent.Parent.BillboardGui.Enabled = true
end)

ClickDetect.MouseHoverLeave:Connect(function()
	script.Parent.Parent.BillboardGui.Enabled = false

end)
local DoorClosing

Is the issue, as you are rotating it from the position it started off from, instead you want it to go back to the original position, so you do not need math.rad(45) instead you could replace this by 0, due to the CFrame.Angles now being (0, 0, 0) you can remove that part completely.

Leaving only

{CFrame = DoorRoot.CFrame}

So your DoorClosing variable would be:

local DoorClosing = TweenService:Create(DoorRoot, Info, {CFrame = DoorRoot.CFrame})
1 Like