I’m attempting to get my object to spin smoothly, and I have come across the issue that it doesn’t change position when the player who will be wearing the object will rotate, jump, etc, so I was primarily wondering if there was a way to fix that issue and make it stay the way it is in the beginning of the video.
local tweenInfo = TweenInfo.new(
0.1, -- Time (duration of the tween in seconds)
Enum.EasingStyle.Linear, -- Easing style (you can adjust this as needed)
Enum.EasingDirection.InOut, -- Easing direction (you can adjust this as needed)
0, -- Repeat count (-1 for infinite looping)
false, -- Reverses the tween (set to false if you want the rotation to be one-way)
0 -- Delay time before starting the tween (0 means no delay)
)
while wait(0.1) do
local tweenDone = false
local tweenMath = Vector3.new(360,0,0) + Vector3.new(part.Orientation.X, part.Orientation.Y, part.Orientation.Z)
local tweenGoal = {
Orientation = tweenMath -- Final rotation in degrees (360 degrees around the Y axis)
}
if tweenDone == false then
local tween = TweenService:Create(part, tweenInfo, tweenGoal)
tween:Play()
tweenDone = true
tween.Completed:Connect(function()
tweenDone = false
end)
end
end
That’s because you’re tweening the orientation. Also, for things simple as this, I recommend doing something else instead.
local angle = 0
while true do
part.CFrame *= CFrame.Angles(math.rad(angle), 0, 0) -- Not sure which axis it is, could be Y or Z too.
angle = (angle + game:GetService("RunService").PreRender:Wait()) % 360
end
What it does is it rotates the part on an axis relative to its current CFrame.
The angle variable is incremented by the amount of time passed between the last and current frame.
Then, it uses modulo to wrap the angle between 0 and 360, so it won’t keep stacking and cause a memory leak.
I’m not sure if this works 100% cause I’m on my phone rn, but let me know if it does!