Code Issue - Rotating a part in a model independent of model's rotation

Hello! I have been trying to make these panels that flip every time you jump for some experiments and was having trouble designing a tween to allow for the platform to rotate 180 degrees regardless of the model’s rotation along the hinge part I have. If I don’t have the model oriented in this very specific axis, then the platform part either spins in place, upside down, or in some other strange direction for the rotation. I suspect it has something with performing the rotation relative to object space rather than world space, but I am not the best at using CFrames, so any help would be appreciated.

I have tried using CFrame.fromOrientation() and also tried multiplying by the orientation of the hinge part (the metallic part in the pictures), but neither worked.

Desired Rotation, but it breaks when I rotate the model in any other direction.

Code Snippet, Non-relevant parts removed:

--Preparing the CFrame to be tweened using a CFrameValue that is binded to a signal.
--Probably a better way to do this?
for _, item in ipairs(allParts) do
	if item:IsA("Model") and item.Name == "FlipSwap"then
		table.insert(panels, item)

--Animation Step
local tweens = {}
		for _, model in ipairs(panels) do
			--Ties the CFrame value in the model to the tween to be updated by a tween later.
			local modelPanel = model.Panel
			modelPanel.CFrameState.Value = modelPanel.PrimaryPart:GetPivot()
			table.insert(tweens, TweenService:Create(modelPanel.CFrameState,tweenInfo,{Value = CFrame.Angles(0, 0, -math.pi)*modelPanel.PrimaryPart:GetPivot().Rotation + modelPanel.PrimaryPart:GetPivot().Position}))
1 Like