Children of Cloned model don't exist, even if given a Yield

Hello, I’m trying to clone humanoid models from the Server to the Client but in doing so the children of the Cloned Model don’t exist

PlrDummy = workspace:WaitForChild("PlrDummy"):Clone()
NPCDummy = workspace:WaitForChild("NPCDummy"):Clone()
PlrDummy.Parent = script.Parent.PlayerViewport
NPCDummy.Parent = script.Parent.NPCViewport

PlrDummy.PrimaryPart = PlrDummy:WaitForChild("HumanoidRootPart") -- Infinite Yield, Nil Error if removed.
NPCDummy.PrimaryPart = NPCDummy:WaitForChild("HumanoidRootPart") -- Infinite Yield, Nil Error if removed.

PCamera = Instance.new("Camera")
NCamera = Instance.new("Camera")
PCamera.Parent = script.Parent
NCamera.Parent = script.Parent

print(PCamera.Name)
print(NCamera.Name)
print(PlrDummy.PrimaryPart.Name) -- Returns Nil
print(NPCDummy.PrimaryPart.Name) -- Returns Nil

PCamera.CFrame = PlrDummy.PrimaryPart.CFrame + Vector3.new(1,0,0)
NCamera.CFrame = NPCDummy.PrimaryPart.CFrame + Vector3.new(1,0,0)

script.Parent.PlayerViewport.CurrentCamera = PCamera
script.Parent.NPCViewport.CurrentCamera = NCamera

Unsure as to what’s causing this…

What the Client has:
image

vs what the client SHOULD have:
image

Yes, everything has Archivable set to true.

1 Like

Could you try change the first line of your code with
PlrDummy = workspace:WaitForChild("PlrDummy"):WaitForChild("HumanoidRootPart"):Clone()
I think PlrDummy was cloned before all of PlrDummy’s children replicated.

2 Likes

Doing this causes an Infinite Yield.

2 Likes

Oh, sorry my bad.

workspace:WaitForChild("PlrDummy"):WaitForChild("HumanoidRootPart")
PlrDummy = workspace:WaitForChild("PlrDummy"):Clone()

will remove your warning.
However, to clone your model properly, you should implement some logic that waits for all children (and descendants) to be replicated before cloning the model. ( or you can listen to DescendantAdded event of PlrDummy and clone descendant to cloned PlrDummy. It is recommended )

you may refer to Wait for model to be fully replicated to client?

3 Likes

This seemed to be the issue, thanks for your help!

1 Like