Tweening CFrame.Angles is rotating my part in every direction

Hey, so I’m experiencing a weird thing with my script which has never happened to me before.

So, I’m trying to tween a rotation with CFrame.Angles, which I have done before, but now it just rotates everything and a sideways direction, even though only 1 direction was specified.

local TweenService = game:GetService("TweenService")
local rCog = workspace.RedCog
local gCog = workspace.GreenCog
local bCog = workspace.BlueCog

local tweenInfo = TweenInfo.new(
	5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out
)

local tweenRotationRed = 
	{CFrame = rCog.CFrame * CFrame.Angles(math.rad(180),0,0)}

local tweenRotationGreen = 
	{CFrame = gCog.CFrame * CFrame.Angles(math.rad(180),0,0)}

local tweenRotationBlue = 
	{CFrame = bCog.CFrame * CFrame.Angles(math.rad(180),0,0)}


local tween0 = TweenService:Create(rCog, tweenInfo, tweenRotationRed)

local function playGears ()
	tween0:Play()
end

playGears()```

Any help will be much appreciated! <3
1 Like

The solution is probably to just change the axis of the rotation in tweenRotationRed, tweenRotationGreen, and tweenRotationBlue.

I actually did try that, but it did the same thing, just on a different axis. I’m quite confused to why this is happening…

Can you select it with your move cursor? (Mainly to see the axis that it needs to rotate on)

Yeah, I always do that, and it was the first one, as it is in the script.

In studio, rotate the part around the axis you wish for it to rotate around and check the Origin Orientation property of the model in order to determine what values you need to use in order to tween the model’s orientation around the correct axis.

After typing this, I see you’re using BasePart instances and not models, in this case just do the same but check the Orientation property instead.

I did, as I states already. Tried it on all of the axis and on the other 2 gears, and the same weird rotation happened…

Yes, when you rotate the part manually in studio check how the “Orientation” property changes. If two of the components of its Vector3 value are changing then that will indicate that you will need to tween around two axis to achieve the desired rotation.

All 3 of them are changing, but I did notice if it’s 180 degrees as it is right now, the Orientation is just purely 180, 0, 0, like it is in the script, when I’m not changing anything else, I’m pretty confused but thanks for the tip.

Because all 3 components are changing you’ll need to multiply the CFrame value by: CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))

Rotate the part in studio till you reach the desired goal, then just plug in the component values of its Orientation property into the above CFrame.Angles() call.

3 Likes

Seems like that worked, thanks! I’ll mark it as a Solution! Thanks a lot, again! :slight_smile: