Right now I am trying to create a object that will spin around in circle’s. So I moved the PiviotPoint to where if it is rotated it will appear to be rotating in a circle. However PiviotTo is not working how I want it to work, and it’s just teleporting the part instead of tweening it.
Is there anyway to make a smooth tween using PiviotTo, while also delivering the appearance of a part rotating in a circle?
You could create a CFrameValue, set its value to the current CFrame, then tween it to the end CFrame, and then detect the changes of the CFrame value and apply it to the pivot:
local part = script.Parent
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
-1,
true,
0
)
wait(10)
local cframeValue = Instance.new("CFrameValue")
cframeValue.Value = part.CFrame
-- detect value changes
cframeValue:GetPropertyChangedSignal("Value"):Connect(function()
part:PivotTo(cframeValue.Value)
end
-- tween it
tweenService:Create(cframeValue,tweenInfo,{Value = cframeValue.Value * CFrame.Angles(0,math.rad(90),0))}):Play()
For garbage collection i recommend you to delete the CframeValue after the tween ends, also use local scoped variables, because lua reads them faster than global ones, plus you dont need it to be global anyways