I been working on a script that uses a viewport frame to create an x-ray of all characters in the workspace, while the characters do correctly clone to the viewport frame and follow the original, they don’t copy the same animations. I’m still new to Roblox Studio in general and dont know how to copy animations from the original character to the cloned ones.
Here’s the full script:
local viewport = script.Parent
viewport.Visible = false
local viewCam = Instance.new("Camera")
viewCam.Parent = workspace
viewport.CurrentCamera = viewCam
--Makes viewport camera follow the workspace camera
game:GetService("RunService").RenderStepped:Connect(function()
viewCam.CFrame = workspace.CurrentCamera.CFrame
end)
--Just gives me a way to toggle the viewport frame
game:GetService("UserInputService").InputBegan:Connect(function(io, gpe)
if io.KeyCode == Enum.KeyCode.F then
viewport.Visible = true
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(io, gpe)
if io.KeyCode == Enum.KeyCode.F then
viewport.Visible = false
end
end)
for _, part in workspace:GetChildren() do
if part:IsA("Model") then
if part:FindFirstChildOfClass("Humanoid") then
--THis clone the orginal character and puts it on the viewport frame
local clone = part:Clone()
clone.Parent = viewport
--Deletes any clothing and decals
for _, child in clone:GetDescendants() do
if child:IsA("Shirt") or child:IsA("Pants") or child:IsA("Decal") or child:IsA("Texture") then
child:Destroy()
end
end
for _, child in clone:GetDescendants() do
if child:IsA("MeshPart") then
--Guves a red plastic material to the character parts and removes any texture
child.Material = Enum.Material.SmoothPlastic
child.Color = Color3.new(1, 0.231373, 0.0941176)
if child.TextureID ~= nil then
child.TextureID = ""
end
--Clones the current part and gives it a forcefield material before welding it to the original part
--Give the x-ray a black outline
local meshClone = child:Clone()
meshClone.Parent = child
meshClone.Material = Enum.Material.ForceField
meshClone.Color = Color3.new(0, 0, 0)
meshClone.CanCollide = false
meshClone.Massless = true
meshClone.Size *= 1.01
local weld = Instance.new("WeldConstraint")
weld.Parent = child
weld.Part0 = child
weld.Part1 = meshClone
end
end
--Makes the clone character's Cframe follow the original character's Cframe
game:GetService("RunService").RenderStepped:Connect(function()
clone:PivotTo(part.PrimaryPart:GetPivot())
end)
end
end
end
And here’s what it currently looks like in game: