I am trying to clone the player’s character to a viewport frame.
This was simple enough to do at first, but now the studio project is completely destroyed and everything is a buggy mess.
The approach is simple. Clone the player’s characterModel, remove everything that’s not a part or a folder in the model and then parent it to the worldmodel inside of the viewportframe.
The 3 issues are:
1: The rendering is inconsistent and glitchy. The arms are often missing from the rendering of the character.

2: Certain scrips are broken upon respawning, and there are hundreds of errors. I thought this would be fixed by deleting the scripts inside the clones, but apparently not.
3: The character rotation (from all axis) changes upon some respawns.

I know I post a lot here, but I have spend hours trying to make this work, and every time I try something it only breaks further
Any help or guidance is appreciated.
-- LocalScript in StarterGui
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local playerListGui = script.Parent.playerList
local frame = playerListGui:WaitForChild("frame")
local textLabelTemplate = game.ReplicatedStorage:WaitForChild("TextLabel") -- Assuming you have a TextLabel template in ReplicatedStorage
local viewportFrameTemplate = game.ReplicatedStorage:WaitForChild("ViewportFrame") -- Assuming you have a ViewportFrame template in ReplicatedStorage
-- Function to clone the character model
local function cloneCharacterModel(player)
local character = player.Character or player.CharacterAdded:Wait()
if character then
character.Archivable = true
local clone = character:Clone()
return clone
end
end
-- Function to update the player list
local function updatePlayerList()
-- Clear existing player labels
for _, existingLabel in pairs(frame:GetChildren()) do
if existingLabel:IsA("TextLabel") then
existingLabel:Destroy()
end
if existingLabel:IsA("ViewportFrame") then
existingLabel:Destroy()
end
end
-- Create and position player labels
local yOffset = 0.15
local players = game.Players:GetPlayers()
for i, player in pairs(players) do
local playerLabel = textLabelTemplate:Clone()
playerLabel.Text = player.Name
playerLabel.Parent = frame
local viewportFrame = viewportFrameTemplate:Clone()
viewportFrame.Parent = frame
local characterClone = cloneCharacterModel(player)
if characterClone then
local children = characterClone:GetChildren()
for index, child in pairs(children) do
if not child:IsA("BasePart") or child:IsA("Folder") then
child:Destroy()
end
end
characterClone.Parent = viewportFrame.WorldModel
characterClone:MoveTo(Vector3.new(1.5,-7,-4))
characterClone.HumanoidRootPart.Anchored = true
end
if i == 1 then
playerLabel.Position = UDim2.new(0.05, 0, 0.001, 0)
viewportFrame.Position = UDim2.new(0.47, 0, 0, 0)
for _, v in pairs(characterClone:GetChildren()) do
v.Orientation = Vector3.new(0,-20,0)
end
else
playerLabel.Position = UDim2.new(0.05, 0, yOffset, 0)
viewportFrame.Position = UDim2.new(0.47, 0, yOffset, 0)
yOffset = yOffset + playerLabel.Size.Y.Scale -- Use scale for vertical spacing
end
end
end
-- Initial update
updatePlayerList()
-- Connect to PlayerAdded and PlayerRemoving events
game.Players.PlayerAdded:Connect(updatePlayerList)
game.Players.PlayerRemoving:Connect(updatePlayerList)
character.wearing.ChildAdded:Connect(updatePlayerList)
character.wearing.ChildRemoved:Connect(updatePlayerList)
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.Tab then
if gameProcessedEvent == false then
if frame.Visible == true then
frame.Visible = false
elseif frame.Visible == false then
frame.Visible = true
end
end
end
end)
