Hi there. I am currently working on a viewport character system, in which the player’s character gets cloned to a viewport frame.
Continuing on, I am having a slight problem with getting it working. I’ll show the code and explain it below.
local char = player.Character or player.CharacterAdded:Wait()
local viewPortFrame = script.ViewportFrame
local function addToViewPort()
local newViewPortFrame = viewPortFrame:Clone()
newViewPortFrame.Name = char.Name
newViewPortFrame.Parent = workspace.TeamSelect.TeamSelectHumRoot.SurfaceGui
local newChar = char:Clone()
newChar.Parent = viewPortFrame
local camera = Instance.new("Camera", workspace)
camera.CFrame = CFrame.new(newChar.PrimaryPart.Position + (newChar.PrimaryPart.CFrame.lookVector * 3), newChar.PrimaryPart.Position)
camera.Parent = newViewPortFrame
end
The only lines of code not working are the lines that change character’s properties, and the viewport frame’s name is actually being renamed to the character’s name, which means the character isn’t a nil game object.
I’ve searched for solutions on discord, roblox developer hub, etc. Nothing comes up.
(And yes, I do call the function later in the code, so don’t ask me about that)
I’ve already explained that the lines erroring are when I try and change the characters properties. When I localize the character, it doesn’t give me an error, and it actually changes the viewport’s name to the character’s name, which means the character isn’t nil.
Did that, although using “player.Character or player.CharacterAdded:Wait()” is more secure in making sure the script doesn’t run before the character get’s added.
i think newChar might be nil, by default the characters have its Archivable property to false, meaning it cannot be cloned, try setting the Archivable to true, then try cloning it