"Attempt to index nil with 'CFrame'" error despite script working fine before

I am trying to eject a casing on the server side whenever a gun is fired from the player. The entire script is working fine, but I decided to make the casing a model with a cylinder so it can roll and a sphere on one end so it doesn’t always stand up.

However, suddenly my script just decided to not work and error on me?

-- Assume the casing variable is declared before
local CasingPrim = Casing.PrimaryPart -- declare primary part variable
Casing.Parent = workspace.Debris
--[[Error here]] CasingPrim.CFrame = player.Character:FindFirstChild("CaseExit", true).CFrame * CFrame.Angles(0, math.rad(90), 0)
local offsetcframe = CasingPrim.CFrame + CasingPrim.CFrame.LookVector * offset
CasingPrim:ApplyImpulse(offsetcframe.Position * CasingPrim.AssemblyMass)
Debris:AddItem(Casing, 10)

Looks like CasingPrim gets destroyed, try printing it. If it prints nil, then its getting destroyed somehow. Where is this part stored?

It is a part of the model which is a mesh.

Is there a script that calls :Destroy() on members of workspace.Debris?

Are you referring to Debris:AddItem(Casing, 10)?

no, because that is called after the error. it will not run. i mean any other script in your game that could be deleting things.

Nothing else is deleted in the game

This is a pretty obvious fault. Casing has no primary part. Figure out why

I did set its primary part, still the same error.

Observe the primary-part at runtime. You will see that it is not there. Make this observation on the same end of the network that the above code is running on

They all have a primary part when running?

Ah. Don’t mind me then. I scrolled further right and noticed you have a second instance of indexing a CFrame:

player.Character:FindFirstChild("CaseExit", true)

This is likely the cuplrit; no descendant of the character named “CaseExit” could be found

That is part of the gun where the case should be spawning from, and it worked fine previously and because of that I’m not sure how to fix it.