How would I rotate a part around a point using Tweenservice?

I’m trying to make a part rotate around a point smoothly around a point using tweening. The part is rotating around the set point, but it rotating oddly. The part is sliding backwards slightly while rotating.

This is what kept happening:
robloxapp-20241203-2030472.wmv (442.5 KB)

Here is the code:

local click_detector = script.Parent.ClickDetector
local rotationpart = script.Parent.rot
local TweenServ = game:GetService("TweenService")
local debounce = false
local open = false

function rotate()
	local u = rotationpart.CFrame * CFrame.Angles(0,math.rad(120),0) * CFrame.new((script.Parent.Part.Size.X)/2,0,0) -- part set to rotate 120 degrees around the rotation part 
	local u2 = rotationpart.CFrame * CFrame.Angles(0,math.rad(0),0) * CFrame.new((script.Parent.Part.Size.X)/2,0,0) -- part set to rotate back to its original orientation
	if not debounce then
		local tween 
		if not open then
			tween = TweenServ:Create(script.Parent.Part, TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = u})
			open = true 
		else
			tween = TweenServ:Create(script.Parent.Part, TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = u2})
			open = false
		end
		debounce = true
		tween:Play()
		tween.Completed:Wait()
		debounce = false
	end

end

click_detector.MouseClick:Connect(function()
	rotate()
end)

Have you tried welding a part to a center part, which you will use as a rotation point, and then just using tweenService to tween the orientation of that center part?
If my assumption that you want to make a swing door is correct then it should give you the result you want

How it set up:

image

Script
local Tween = game:GetService("TweenService")
local Info = TweenInfo.new(1)

local click = script.Parent
local RotatePoint = script.Parent.Parent.Parent.Center

local Debounce = false
local Opened = false

local function Rotate()
	if Debounce then return end
	Debounce = true
	if Opened == false then
		Opened = true
		local swing = Tween:Create(RotatePoint, Info, {Orientation = RotatePoint.Orientation + Vector3.new(0,90,0)})
		swing:Play()
		swing.Completed:Connect(function()
			Debounce = false
		end)
	elseif Opened == true then
		Opened = false
		local swing = Tween:Create(RotatePoint, Info, {Orientation = RotatePoint.Orientation + Vector3.new(0,-90,0)})
		swing:Play()
		swing.Completed:Connect(function()
			Debounce = false
		end)
	end
end

click.MouseClick:Connect(Rotate)

if you have any question feel free to ask!

2 Likes

Funny thing is, I just came to conclusion you did a a few hours ago. Thanks for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.