I've been working on a project that uses viewport frames to show the world around it (Kind of like how a mirror would work) and I keep getting this error. It works for everything inside the game except cloning a players character. I have tested models other than the player too and they work fine.
The line with the error:
v:Clone().Parent = script.Parent.Parts;
Also I have done some debugging and its not the script.Parent part, its the v:Clone().Parent part.
Full script:
local viewportFrame = script.Parent;
local part = workspace.Mirror;
local viewportCamera = Instance.new("Camera");
viewportFrame.CurrentCamera = viewportCamera;
viewportCamera.Parent = viewportFrame;
repeat wait() until game.Players.LocalPlayer.Character;
repeat wait() until game.Players.LocalPlayer.Character.Head;
viewportCamera.CFrame = CFrame.new(part.Position, part.Position+part.CFrame.LookVector);
game:GetService("RunService").RenderStepped:Connect(function(step)
for i,v in pairs(script.Parent.Parts:GetChildren()) do
v:Destroy();
end;
for i,v in pairs(workspace:GetChildren()) do
if (not v:IsA("Terrain") and not v:IsA("Camera")) then
local ln = "";
local s,e = pcall(function()
ln = v.Name;
v:Clone().Parent = script.Parent.Parts;
end);
if (not s) then warn(ln.. " cannot be re-parented || error || ".. e) end;
end;
end;
end);

5 comments
this is under runservice renderstepping so that will cause tons of lag. Im cloning items in workspace to the viewport frame.
I also use ; for js and the habit goes over
But its commonly used in tables or dictionaries. But you can use it if you want.
well it still doesn't fix the issue I usually can fix this but it only happens with the player's character. Is it because it is a character of a player?
Oh it's because the player's character is not Archivable. I just need to set that to true!