Getting rid of an intentional error

Hopefully I worded my title right.
So basically I have a register system so that if player leaves, the NPC is destroyed while in the process of going to the register but i keep getting this error and I want to get rid of it.

Model:GetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.
				local dummy = randomRig

				local cframe = Instance.new("CFrameValue")
				
				if not dummy:GetPrimaryPartCFrame() then
					return
				else
				cframe.Value = dummy:GetPrimaryPartCFrame()
				cframe.Changed:Connect(function(value)
					dummy:SetPrimaryPartCFrame(value)
				end)
				end
1 Like

Just wrap the code that’s erroring in a pcall. That should cover it up (if it doesn’t affect the rest of your code).

you removed the NPC, so the primaryPart would not exist anymore. Check if the dummy == nil instead, this should fix your problem.

or, use a while loop to wait for the NPC to respawn/regen

1 Like

Check if PrimaryPart exists before doing the Method

cframe.Changed:Connect(function(value)
	if dummy.PrimaryPart then
		dummy:SetPrimaryPartCFrame(value)
	end
end)

read the error first. it says “no PrimaryPart has been set”. means the PrimaryPart of the model you are calling is not set or doesn’t exist or has been destroyed. from your code im guessing “Dummy” is a basic roblox rig and has a HumanoidRootPart, you should set the HumanoidRootPart as the PrimaryPart and you should be good to go.

1 Like