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)
