Viewport Frame not loading properly

Here is what happens to my inventory UI when there is no delay to load:
image

And where it is delayed by 2 seconds to load:
image

Here is my load function:

function update(name)
	local interactItemButton = inventoryGui:WaitForChild("InteractItemButton"):Clone()
	local interactItemVFrame = inventoryGui:WaitForChild("InteractItemVFrame"):Clone()
	
	interactItemButton.Parent = inventoryFrame
	interactItemVFrame.Parent = interactItemButton
	interactItemVFrame.BackgroundTransparency = 0
	
	local worker = replicatedStorage:WaitForChild("Workers"):WaitForChild(name):Clone()
	
	local camera = Instance.new("Camera", interactItemVFrame)
	camera.CFrame = CFrame.new(worker.PrimaryPart.Position - Vector3.new(0, 0, -8))
	
	interactItemVFrame.CurrentCamera = camera
	worker.Parent = interactItemVFrame
			
	table.insert(clickConnects, interactItemButton.MouseButton1Down:Connect(function()
		updateSelected(name)
	end))
end

Thank you for any help/suggestions!

1 Like

This is likely caused by worker.PrimaryPart not being loaded in, try using worker:WaitForChild("PrimaryPartName").Position

1 Like

Thank you so much! For me now I can decrease the waiting time by a lot, but it still has to be .5 seconds (which is fine i guess). Just out of curiosity, are there any other improvements I could make?

Hmm thats interesting, could you remove the wait and identify the issue by adding more debugging (like printing out “made it here” after a line).

1 Like

where are you placing the delay?

1 Like

I do
wait(2)
for each item:
update()

All the models are loaded, and the script runs everything, it just doesn’t appear in the viewportframe