Scripting Primary Part CFrame error

I’m having a problem where where even after setting the primary part of the model the script has an error. Am I doing something wrong? (Btw the script’s location can be seen at the beginning of the video)

local vf = script.Parent
local camera = Instance.new("Camera", vf)
vf.CurrentCamera = camera
local popsicle = script.Parent.Popsicle

popsicle:SetPrimaryPartCFrame(CFrame.new(0,0,0))

local cameraPosition = Vector3.new(3, 3, 3)
camera.CFrame = CFrame.new(cameraPosition, script.Parent.Popsicle.Prime.Position)
1 Like

Is Prime not archivable by any chance?

It’s set to Archivable = true

1 Like

Can you show us the model after the error?

I pressed play, and here is the location of the model in my GUI


Edited topic post, for some reason it cut off a line of code. Fixed

1 Like

I mean the models children and the models property.

1 Like

I tested this in studio and I was able to reproduce it. Adding a brief wait(1) at the beginning of the script fixed it.

This might have something to do with the order in which objects are replicated. I wouldn’t call adding a fudgy wait at the beginning a fix yet.

2 Likes

I’m pretty sure the issue is that not everything is cloned by the time the script starts executing.
This should fix it.

local p = popsicle.PrimaryPart or popsicle:GetPropertyChangedSignal("PrimaryPart"):Wait()
3 Likes

That fixed it, thank you!
That is so weird. I wonder if it’s because the script runs before the other objects are replicated into the GUI maybe? I’m not sure. Quite weird I would say myself
Edit: Both worked, but @Halalaluyafail3 Your solution of waiting for the property changed is really smart, as it waits until it exists. Thank you all so much!

1 Like

Something like this would work better

repeat
	wait()
until popsicle.PrimaryPart ~= nil

Not sure why you would constantly need to check, and if it already does exist, then its yielding for no apparent reason.

2 Likes