Parenting Player to ViewportFrame

Hi, i’m trying to parent the player’s character to the viewport by cloning their character when they join. It gave me a warning saying that it’s parented to Players. Here is my code:

game.Players.PlayerAdded:Connect(function(player)
	
	player:Clone()
	player.Parent = game.StarterGui.MainGUI.Intro:WaitForChild("ViewportFrame")
end)
1 Like

You’re cloning the actual Player instance and not the character, which isn’t allowed.

Instead, get the character and then copy and paste that into the ViewportFrame. Also, if you’re cloning the character to the StarterGui, then it won’t replicate to the clients because StarterGui is held on the server. Instead, clone it to a player’s PlayerGui.

game.Players.PlayerAdded:Connect(function(player)
	
	local character = player.Character or player.CharacterAdded:Wait()
    character.Archivable = true
    local clonedCharacter = character:Clone()

	clonedCharacter.Parent = game.Player.WooleyWool.MainGUI.Intro:WaitForChild("ViewportFrame")
      -- Don't clone it to the StarterGui, instead clone it to a player's PlayerGui like I did above
end)

Also, there is a much better way to do this. I would rather you do this all in a local script so you can fetch the character easily and make your code much cleaner.

Better version:

-- In a local script

local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character.Archivable = true

local vpf = script.Parent

character:Clone().Parent = vpf
2 Likes

That is not going to work since the character model is not Archivable
Here is the working code:

local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character.Archivable = true
local vpf = script.Parent

character:Clone().Parent = vpf

I already mentioned that in my reply.

1 Like

Would you know how to have the player’s animations attached to the character?

Please use the search bar and search for this question before asking.

This post might be of use to you:

I tried using it but i have an error with this line. It said it expected ( or )

viewportFrameCamera.CFrame = viewportFrameCharacter.HumanoidRootPart.CFrame * CFrame.new(0, 0, -5.5, 0, 1, 0 0)

You forgot to add a comma between the two 0’s at the end.

Still caused more issues with Local Player