How to make sure that changing CFrame is always proper logically?

So basically, I have an item rotation system and it rotates the item on it’s CFrame, but for example once I turn them randomly, when I click a left button to rotate it left, the item will rotate Up. I tried to instead rotate it on it’s Vector3 but the same issue occured. Any ways I can fix it, so that it always rotates logically? (e.g When I press a up button it always rotates Up)

Here’s my code:

local Direction = c:FindFirstChildWhichIsA("StringValue")
	if Direction and debounce == false then
		debounce = true
		local rotateTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
		local currentOrientation = PickedItem.Orientation
		if Direction.Name == "Up" then
			local rotateUpTween = tweenservice:Create(PickedItem, rotateTweenInfo, {CFrame = PickedItem:GetPivot() * CFrame.Angles(math.rad(-90),0,0)})
			rotateUpTween:Play()
			--PickedItem:PivotTo(PickedItem:GetPivot() * CFrame.Angles(math.rad(-90), 0, 0))
		elseif Direction.Name == "Down" then
			local rotateDownTween = tweenservice:Create(PickedItem, rotateTweenInfo, {CFrame = PickedItem:GetPivot() * CFrame.Angles(math.rad(90),0,0)})
			rotateDownTween:Play()
			--PickedItem:PivotTo(PickedItem:GetPivot() * CFrame.Angles(math.rad(90), 0, 0))
		elseif Direction.Name == "Left" then
			local rotateLeftTween = tweenservice:Create(PickedItem, rotateTweenInfo, {CFrame = PickedItem:GetPivot() * CFrame.Angles(0,0,math.rad(90))})
			rotateLeftTween:Play()
			--PickedItem:PivotTo(PickedItem:GetPivot() * CFrame.Angles(0, 0, math.rad(90)))
		elseif Direction.Name == "Right" then
			local rotateRightTween = tweenservice:Create(PickedItem, rotateTweenInfo, {CFrame = PickedItem:GetPivot() * CFrame.Angles(0,0,math.rad(-90))})
			rotateRightTween:Play()
			--PickedItem:PivotTo(PickedItem:GetPivot() * CFrame.Angles(0, 0, math.rad(-90)))
		end
end

Thanks! :smiley:

I’ve found that orientation with CFrames can be funny sometimes. You should try experimenting with the different axis to see which one you need to rotate to do what you want. So, if rotating Z with math.rad(90) instead rotates it upwards, try doing that with the Y axis instead. I’m not that familiar with how they work as everything I do with them is mostly trial and error, but sometimes they’ll interpret different axis in different spots of the parameters you provide. e.g. (YXZ) instead of (XYZ).

Again, I’m stupid with these. Take this with a grain of salt and just try different stuff until it works.
Or if someone could come along and give an actual explanation that’ll make me look like an idiot, that would be appreciated too.

1 Like

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