Tween Rotation isnt working. Help


as seen in the video above, the doors will open up, but the right door closing rotates weirdly.
here is my code

local TweenService = game:GetService("TweenService")
local inputService = game:GetService("UserInputService")
local part = script.Parent.Parent.right

local info = TweenInfo.new(
	1,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)


script.Parent.Triggered:Connect(function()

	local Goals =
		{
			Rotation = Vector3.new(0, 180, 0);
		}
	local tween = TweenService:Create(part, info, Goals)

	tween:Play()

	wait(4)

	local Goals =
		{
			Rotation = Vector3.new(0, 90, 0);
		}
	
	local tween = TweenService:Create(part, info, Goals)
	
	tween:Play()

end)

i have tried a ton of things.
pls help

1 Like

what is the right doors initial rotation? maybe you could try something like this

local goal = {
  goal.Rotation = Vector3.new(part.Orientation.X, --[[your number value goes here]], part.Orientation.Z)
}

Also i suggest using Tween.Completed:Wait() instead of the wait(), it’ll wait until the tween is complete before it starts running the rest of the code

1 Like

still doesnt work :frowning: ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

thanks! :grinning: ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

I believe the problem is from using Rotation instead of CFrame. The math might be a little weird since the TweenService interpolates linearly and rotations aren’t exactly a “vector” value in anything but form.

Using CFrames should probably solve the problem.

local TweenService = game:GetService("TweenService")
local inputService = game:GetService("UserInputService")
local part = script.Parent.Parent.right


local initialCFrame = part.CFrame
-- initialCFrame rotated 90 degrees
local finalCFrame = part.CFrame * CFrame.Angles(0, math.rad(90), 0)

local info = TweenInfo.new(
	1,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local isPlaying = false -- Added this, you can remove it.
script.Parent.Triggered:Connect(function()
	if isPlaying then return end -- added
	isPlaying = true -- added
	local Goals =
		{
			CFrame = finalCFrame
		}
	local tween = TweenService:Create(part, info, Goals)

	tween:Play()

	task.wait(4)

	local Goals =
		{
			CFrame = initialCFrame
		}

	local tween = TweenService:Create(part, info, Goals)

	tween:Play()
	tween.Completed:Wait()
	isPlaying = false -- added
end)

yay it worked tysm ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

1 Like