I’m trying to clone the player’s character so I can then put it in a viewport frame, this is the script:
local plr = game.Players.LocalPlayer
local plrChar = plr.Character or plr.CharacterAdded:Wait()
local vpFrame = script.Parent
-----------------------
plrChar.Archivable = true
local char = plrChar:Clone()
char.Parent = vpFrame
for i, v in pairs(plrChar:GetChildren()) do
local clonedPart = v:Clone()
clonedPart.Name = v.Name
clonedPart.Parent = char
end
plrChar.Archivable = false
local vpCam = Instance.new("Camera")
vpCam.CFrame = CFrame.new(char.HumanoidRootPart.Position + (char.HumanoidRootPart.CFrame.LookVector * 3), char.Head.Position)
vpCam.Parent = vpFrame
vpFrame.CurrentCamera = vpCam
But when I play the game, open Players, then go inside the viewport frame, there’s nothing inside the cloned character, no humanoid root part, no head, nothing (which makes the script not work, it says that humanoid root part isn’t a valid part of model)
Sometimes the player doesn’t fully load in before firing CharacterAdded. Try waiting for CharacterAppearanceLoaded instead. There are plans to make the events more intuitive, but they’ve been put on hold:
So for now, is it advisable to rely on CharacterAppearanceLoaded instead of CharacterAdded until this update is live for all games? (This may post may be off-topic but I didn’t realized the Character isn’t parented yet to the DataModel once CharacterAdded fired)
Often you don’t need to have the character initialized, in which case it’s more convenient to use CharacterAdded. I’d recommend using CharacterAppearanceLoaded though, yeah. Ideally I’d use a custom Bindable that fires when LoadCharacter returns, but that’d be a bit of a pain to code so I wouldn’t recommend that for every game.
(The current ordering is really unintuitive, I can understand the confusion.)
the problem is the stuff inside the character model isn’t cloned with the character, so I used In Pairs to clone everything inside the character, but even that didn’t work, when I open the viewport there’s the character, but there’s nothing inside it
I understand what u mean, but if you read my post carefully, this isn’t my problem, the problem is that what’s inside the character (the actual body parts), is not getting cloned and parented to the viewport frame, even though I’m using that In Pairs
It was a stupid mistake, the character was being cloned before the parts inside it could load, I removed the In Pairs, added a WaitForChild and it worked fine, since cloning an item clones all its children too