CFrame with PrimaryPart problem

I am trying to rotate a model inside of a viewport. I am getting the error that the PrimaryPart doesn’t exist or has been changed which it hasn’t at all. I tried seeing if me changing the parent of the model ruined but that was not the case. The following code is here:

local runService = game:GetService("RunService") 
local startingTick = tick()

local vf = script.Parent

local cf =, 0, 0))
script.Rifle.Parent = vf

local camera ="Camera", vf)
vf.CurrentCamera = camera

local cameraPosition =, 0, 2)
camera.CFrame =, script.Parent.Rifle:GetPrimaryPartCFrame())

function makeBrickMove()
	while true do 
		local diff = tick() - startingTick 
		script.Parent.Rifle:SetPrimaryPartCFrame(CFrame.Angles(0, 10*math.rad(diff), 0)) 



  Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.  -  Client - LocalScript:8

The Model:
Screenshot 2021-05-15 115316

Thanks if you could help

change this to this

local cf =, 0, 0))


local cf =, 0, 0)

Thanks for helping me simplify this, but this does not help my error.

could you show the explorer?b


how does the model property look when test playing game?

this line feels weird

camera.CFrame =, script.Parent.Rifle:GetPrimaryPartCFrame())

The model looks like this:

You should check if the PrimaryPart exists first.

if Model.PrimaryPart then
   -- Code.

So actually I have found out that since I changed the parent of the model it reset the PrimaryPart to nil for some reason. I fixed it with this simple line of code:

model.PrimaryPart = part

I appreciate the help though :slight_smile: