"Rotation cannot be assigned to" Error

I have this script, right? Basically finds everything inside a folder and rotates it into the right direction. And this error keeps popping up even when I think it’s all correct. Here’s the script.

for i,npc in pairs(game.Workspace.ViewportFrames:GetDescendants()) do
	if npc:IsA("Model") then 
		print(npc.Name)
		npc:GetPivot().Rotation = Vector3.new(0,180,0)
	end
end
3 Likes

You might want to multiply GetPivot by CFrame.Angles(0,math.pi,0) (and then apply using PivotTo()) since:

  1. you’re getting the Pivot, not setting it
  2. Rotation cannot be set in any CFrame
1 Like

.rotation is a read only value trying using PivotTo? I’m pretty sure that’s what it is

1 Like

:GetPivot() returns a CFrame, which has a Position and Rotation value. Position is a Vector3, and Rotation is a CFrame without a position. To set the rotation, use:

local c = npc:GetPivot()
npc:SetPivot(CFrame.new(c.Position) * CFrame.Angles(0,math.rad(180),0))

This creates a new cframe with no rotation, and then rotates it 180 degrees on the Y axis. It sets the npc’s pivot to that.

2 Likes