Tweening Rotation

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
local tweenMath = Vector3.new(part.Orientation.X, part.Orientation.Y, part.Orientation.Z) + Vector3.new(360,0,0)

right? or no?

If you’re saying if it works, it unfortunately didn’t

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!

1 Like

It’s giving me

Workspace.Handle.Handle.cyclotron.Script:9: invalid argument #2 (Vector3 expected, got CFrame)

as an error

Woops, it’s part.CFrame *= not part.CFrame +=, my bad

1 Like

Hah! It works kind of, it spins the object it sits in with it due to them being welded together but it at least spins and moves in the directions lol

1 Like

Ah, then you can do the same method on the weld’s CFrame too, if that would make it better.

1 Like

alrighty, I’ll give that a shot and then get back to you

1 Like

It worked! I just redid the weld and made the C0 the base, and C1 the cylinder and then did the positioning to the C0 and it worked!

1 Like

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