Roblox spinning a part with CFrames

Hello,

I’ve been having some issues with continuously spinning a part via CFrames (I need to do it with CFrames to update the welds I have attached).
I have the following code:

local function SpinPart(part)
    local TempTweenInfo = TweenInfo.new(
        part:WaitForChild("RotationSpeed").Value,
        Enum.EasingStyle.Linear,
        Enum.EasingDirection.Out,
        -1
    )
    local RotationVector = part:WaitForChild("RotationVector").Value
    local TempTween = TweenService:Create(part, TempTweenInfo, {CFrame = part.CFrame * CFrame.Angles(RotationVector.X, RotationVector.Y, RotationVector.Z)})
    TempTween:Play()
end

RotationVector is a Vector3Value in the part which shows its intended orientation destination
RotationSpeed is a IntValue in the part which shows the tween duration

But it makes the spin bricks do some interesting spinning:

Here is an example of what’s going on so you can easily replicate my issue:
https://www.roblox.com/library/6714836489

Any ideas you could give would be great,
Tweakified

What is your vectorvalue? It might be too high.

The RotationVector used in the video was 0, 0, 360
However the one I used in the file I sent was 0, 360, 0

Rotation is measured in radians in CFrame. Did you convert?

2 Likes

You can convert degrees to radians with math.rad().

No, but as part of my debug process I changed it to:
CFrame.Angles(math.rad(RotationVector.X), math.rad(RotationVector.Y), math.rad(RotationVector.Z))})
And the part didn’t rotate at all.

Yeah because 360 degrees is basically the starting orientation of the part so it takes the shortest route which is basically doing nothing?

You might want to increase the rotation by 90 each time.

1 Like

Just tried this:

local function SpinPart(part)
	local TempTweenInfo = TweenInfo.new(
		part:WaitForChild("RotationSpeed").Value / 3,
		Enum.EasingStyle.Linear
	)
	local RotationVector = part:WaitForChild("RotationVector").Value
	local TempTween1 = TweenService:Create(part, TempTweenInfo, {CFrame = part.CFrame * CFrame.Angles(math.rad(RotationVector.X) / 3, math.rad(RotationVector.Y) / 3, math.rad(RotationVector.Z) / 3)})
	local TempTween2 = TweenService:Create(part, TempTweenInfo, {CFrame = part.CFrame * CFrame.Angles(math.rad((RotationVector.X) / 3) * 2, math.rad((RotationVector.Y) / 3) * 2, math.rad((RotationVector.Z) / 3) * 2)})
	local TempTween3 = TweenService:Create(part, TempTweenInfo, {CFrame = part.CFrame * CFrame.Angles(math.rad(RotationVector.X), math.rad(RotationVector.Y), math.rad(RotationVector.Z))})
	while true do
		TempTween1:Play()
		TempTween1.Completed:Wait()
		TempTween2:Play()
		TempTween2.Completed:Wait()
		TempTween3:Play()
		TempTween3.Completed:Wait()
	end
end

And it works!
Thanks

Yay! Glad i could help you. :smiley: