CFrame is nil but part isn't?

I am trying to make a cell shading script. But when I try to use CFrame of the part it says it is nil. Even when I print the cframe it says nil. BUT when I print the part, it works. How do I fix this?

function module.SetCellshade(Parent,Cellshade,Camera,Color,Thickness)
	Cellshade.CFrame = Parent.CFrame + (Camera.CFrame.LookVector * Thickness)
end

From the screenshot of the output, something has been printed nil…so the script may be trying to prefrom arithmetic on something other than the part that keeps returning nil.

Can you show us your full script for ReplicatedStorage.Cellshade?

local module = {}

function module.SetCellshade(Parent,Cellshade,Camera,Color,Thickness)
	local ThickVector = Vector3.new(Thickness,Thickness,Thickness)
	Cellshade.CFrame = Parent.CFrame
	Cellshade.Position += (Camera.CFrame.LookVector * ThickVector)
	Cellshade.Size = Parent.Size + (ThickVector * Vector3.new(1.2,1.2,1.2))
	Cellshade.Color3 = Color
end

return module

It means that you attempted to add nil to Vector3, Parent must be nil in this case

try printing the parent and the parent’s cframe to see if it has a value.

The parent printing works, the cframe is still nil. But I can see the parent in workspace.

Maybe Parent is not a BasePart? Try doing print(typeof(Parent)). If it is a model, then you must use :GetPrimaryPartCFrame() or an alternative CFrame function of models.

Perhaps the part was created locally? Check how the part was created, and try seeing your world on the server side.

Otherwise, you can also try :PivotTo(), it works with both models and baseparts. I don’t recommend :SetPrimaryPartCFrame, as it needs to be a model, requries a primary part, it often slightly offsets the model and it is getting deprecated soon.

1 Like

It is a simple part I added into the workspace by pressing the plus button. @Awesome_Dev5000 Before playing the game.