CFrame rotation switches back to original rotation instantly

In this script, Im trying to set the rotation of a primary part (In this case a union of a model) to the current angle + 90 degrees. However, whenever I try this, it almost instantly resets back to the original angle without sticking.

I am completely cooked on how to solve this and have been trying for a while.

	if key.UserInputType == Enum.UserInputType.Keyboard then
				if key.KeyCode == Enum.KeyCode.R then
					if rotationlock == false then
						Outline1x1:SetPrimaryPartCFrame(Outline1x1:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, math.rad(90)))
						
					end
				else
					
					return
					end 
			end

I’ve checked through the CFrame dev hub, but couldnt really find a fix to help with my problem, any help is appreciated, example below:

https://gyazo.com/c91e4ed581bf215a14edd15a2f974bcc

The problem could arise from you using :SetPrimaryPartCFrame()
This is clearly a deprecated feature as the Creator Docs state, instead you should move towards better solutions like :PivotTo() or .PrimaryPart.CFrame = ...

So we can do this now:

Outline1x1:PivotTo(Outline1x1:GetPivot() * CFrame.Angles(0, 0, math.rad(90)))

Another equally as likely problem may be that you are calling :SetPriamryPartCFrame() somewhere else as you haven’t showed the full script. Possibly a loop or RunService connection that you are using to update the CFrame to the Player’s mouse position.


Further Reading:

Im pretty sure you’re right about calling other pivot/cframe statements in the script, great call!

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