PrimaryPart is nil, even tho there is clearly a PrimaryPart

The PrimaryPart returns nil, even tho can see in the SS that a PrimaryPart has clearly been set

local Viewport = script.Parent

local Crate = Viewport:WaitForChild('Crate')

local Camera = Instance.new('Camera')
Viewport.CurrentCamera = Camera
Camera.Parent = Viewport
print(Crate.PrimaryPart)
Camera.CFrame = CFrame.new(Vector3.new(0, 2, 12), Crate.PrimaryPart.Position)
1 Like

Perhaps it is a timing issue.
Try
local primaryPart = Crate:WaitForChild(“Primary”)
print(primaryPart)

1 Like

Also try setting the primary part

1 Like

Also make sure the primary part isn’t falling into the void.

I made that mistake once when I wanted to rotate a model using :SetPrimaryPartCFrame() with an invisible primary part as the rotation point, but I forgot that parts are not anchored by default :smile:

5 Likes

All the parts of the model are anchored

1 Like

He has already set the primary part.

Just ran a test - this seems to happen only when the model is a descendant of a GuiBase2d object. This doesn’t happen when the model is located elsewhere and cloned or parented in. If you don’t want to take that route, I was able to mitigate this issue by just adding a wait after your WaitForChild line. May be worth reporting in #platform-feedback because I think it is unexpected behavior, since the PrimaryPart does get set at some point, it just seems to be delayed when the model is inside of a GuiBase2d object for whatever reason.

Edit: Modified my reply a few times after doing more tests.

5 Likes