Sliding doors keep rotating after activation

I made some sliding Doors but now they keep on rotating when i activate them

Video of it
https://streamable.com/mi5hpf

image

In Text Form

local Door1 = script.Parent.Door1

local Door2 = script.Parent.Door2

local Detector = script.Parent.Detector

local TweenServ = game:GetService("TweenService")

local TweenInformation = TweenInfo.new(

1.5,

Enum.EasingStyle.Linear,

Enum.EasingDirection.In,

0,

false,

0

)

local door1Closed = {CFrame = CFrame.new (301.438, 4.062, 12.188)}

local door2Closed = {CFrame = CFrame.new (296.375, 4.062, 12.188)}

local door1Open = {CFrame = CFrame.new (310,4.5,12)}

local door2Open = {CFrame = CFrame.new (280, 4.5,12)}

local Door1Opening = TweenServ:Create(Door1,TweenInformation,door1Open)

local Door2Opening = TweenServ:Create(Door2,TweenInformation,door2Open)

local Door1Closing = TweenServ:Create(Door1,TweenInformation,door1Closed)

local Door2Closing = TweenServ:Create(Door2,TweenInformation,door2Closed)

Detector.Touched:Connect(function(hit)

Door1Opening:Play()

Door2Opening:Play()

wait(5)

Door1Closing:Play()

Door2Closing:Play()

end)

Can you show a gif for it? Also
Did you try checking if the hit is a humanoid and use a debounce? If not then try this

local debounce = false

Detector.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then--check if humanoid, maybe it keeps running because it keeps touching other things
   if not debounce then
    Door1Opening:Play()
    Door2Opening:Play()
    wait(5)
    Door1Closing:Play()
    Door2Closing:Play()
    debounce = true --make the event work again
    end
  end
end)

Hi!

Issue was you were tweening the doors to a new CFrame, however CFrame defines a position and a rotation

To fix it, you should tell the tween the rotation you want the doors to end up in as well. I’ve attached an edited version of your script, let me know if it works!

local Door1 = script.Parent.Door1
local Door2 = script.Parent.Door2
local Detector = script.Parent.Detector
local TweenServ = game:GetService("TweenService")
local TweenInformation = TweenInfo.new(
	1.5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local Door1OriginalRotation = Door1.CFrame - Door1.CFrame.p
local Door2OriginalRotation = Door2.CFrame - Door2.CFrame.p

local door1Closed = {CFrame = CFrame.new (301.438, 4.062, 12.188) * Door1OriginalRotation}
local door2Closed = {CFrame = CFrame.new (296.375, 4.062, 12.188) * Door2OriginalRotation}
local door1Open = {CFrame = CFrame.new (310,4.5,12) * Door1OriginalRotation}
local door2Open = {CFrame = CFrame.new (280, 4.5,12) * Door2OriginalRotation}
local Door1Opening = TweenServ:Create(Door1,TweenInformation,door1Open)
local Door2Opening = TweenServ:Create(Door2,TweenInformation,door2Open)
local Door1Closing = TweenServ:Create(Door1,TweenInformation,door1Closed)
local Door2Closing = TweenServ:Create(Door2,TweenInformation,door2Closed)

Detector.Touched:Connect(function(hit)
	Door1Opening:Play()
	Door2Opening:Play()
	wait(5)
	Door1Closing:Play()
	Door2Closing:Play()
end)