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:
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
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