Clone Command | Creating A Player Clone With Animations

  1. What do you want to achieve?

Simple Clone Command like HD ADMIN - > /clone

image

Also, when a player has animations playing, it will grab the animation tracks from the player and put it on the clone.

This script also checks if your in bloxikin form and clones that bloxikin form as well.

  1. What is the issue?
    R15 FORM :
    image
    BLOXIKIN FORM :
    image

Clone command is causing a weird clone, to be made… It makes you naked, and then clones everything else onto the other player. It also is stuck to the original player.

  1. What solutions have you tried so far?

SERVER SCRIPT : Module that is for the command (yes the command is already set up) “Yes” is a value that will check the player, and in bloxikin form it should have that “Yes” value.

function Clone.Clone(player)
	local event = game.ReplicatedStorage.CloneEvent
	
	if player.Character:FindFirstChild("Yes") then
		event:FireClient(player,"Blox")
	else
		event:FireClient(player,"R15")
	end
	
end

LOCAL SCRIPT : The Local Script in Starter Player Scripts used to create a clone.

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()

game.ReplicatedStorage.CloneEvent.OnClientEvent:Connect(function(rigType)
	
	local humanoid = Character:WaitForChild("Humanoid")
	local head = Character:WaitForChild("Head")
	
	if humanoid and head then
		local newRig = game.ReplicatedStorage.ASSETS["Rig"..rigType]:Clone()
		local newHumanoid = newRig.Humanoid
		local originalCFrame = head.CFrame
		newRig.Name = " "
		for a,b in pairs(Character:GetChildren()) do
			if b:IsA("Accessory") or b:IsA("Pants") or b:IsA("Shirt") or b:IsA("ShirtGraphic") or b:IsA("BodyColors") then
				b.Parent = newRig
			elseif b.Name == "Head" and b:FindFirstChild("face") then
				newRig.Head.face.Texture = b.face.Texture
			end
		end
		Character = newRig
		newRig.Parent = workspace
		newRig.Head.CFrame = originalCFrame
	end
	
end)

NOTE : I HAVE NOT INCLUDED THE ANIMATION PART YET. Just confused on why this is happening with clone…

Could it be caused by the rig i’m using?

1 Like

One issue is you’re not cloning the pants/shirts/accessories so it just moves them to that rig instead of cloning them.

b.Parent = newRig -> b:Clone().Parent = newRig

And then for accessories you may need to use this:
https://developer.roblox.com/en-us/api-reference/function/Humanoid/AddAccessory

I also went ahead and found HD admin’s clone command source:

local container = workspace

local createClone = function(character)
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then

		--Setup clone
		character.Archivable = true
		local clone = character:Clone()
		local cloneHumanoid = clone.Humanoid
		clone.Name = character.Name.."'s HDAdminClone"
		local specialChar = false
		if clone:FindFirstChild("Chest") then
			specialChar = true
		end
		for a,b in pairs(clone:GetDescendants()) do
			if b:IsA("Humanoid") then
				b.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
			elseif b:IsA("BillboardGui") then
				b:Destroy()
			elseif b:IsA("Weld") and b.Part1 ~= nil then
				b.Part0 = b.Parent
				if clone:FindFirstChild(b.Part1.Name) then
					b.Part1 = clone[b.Part1.Name]
				elseif not specialChar then
					b:Destroy()
				end
			end
		end

		--Make clone visible
		--module:SetTransparency(clone, 0)
		clone.Parent = workspace

		--Animations
		local tracks = {}
		local desc = humanoid:GetAppliedDescription()
		local animate = clone:FindFirstChild("Animate")
		if animate then
			for i,v in pairs(clone.Animate:GetChildren()) do
				local anim = (v:GetChildren()[1])
				if anim then
					--anim.Parent = clone
					tracks[v.Name] = cloneHumanoid:LoadAnimation(anim)
				end
			end
			tracks.idle:Play()
		end

		return clone, tracks
	end
end

local clone = function(plr)
	local char = plr.Character
	local hrp = char:FindFirstChild("HumanoidRootPart")
	if hrp then
		local clone = createClone(char)
		local humanoid = clone:WaitForChild("Humanoid")
		humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Subject
		humanoid.HealthDisplayDistance = 25
		humanoid.NameDisplayDistance = 25
		local cloneHrp = clone:WaitForChild("HumanoidRootPart")
		cloneHrp.CFrame = hrp.CFrame * CFrame.new(0, 5, 0)
		clone.Parent = container
		clone.Name = plr.DisplayName
	end
end

You can call it like:

local players = game:GetService("Players")
local target = players.Roblox
clone(target)

Not sure if this would work with your custom rig things, but perhaps you can improvise on that?

2 Likes

So this was a great fix to figuring out how to make a better clone with animations, but the problem is…

When the player wants to clone a bloxikin… It does not clone the bloxikin template/player character.

Instead it does the default R15, and also

It spawns the clone at the exact point of the last clone instead of the new point.

So in all I don’t have a way to clone the bloxikin morph…

image

Why could this be happening?

Here is the new edited code :

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local container = workspace

local createClone = function(character)
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then

		--Setup clone
		character.Archivable = true
		local clone = character:Clone()
		local cloneHumanoid = clone.Humanoid
		clone.Name = " "
		local specialChar = false
		if clone:FindFirstChild("Chest") then
			specialChar = true
		end
		for a,b in pairs(clone:GetDescendants()) do
			if b:IsA("Humanoid") then
				b.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
			elseif b:IsA("BillboardGui") then
				b:Destroy()
			elseif b:IsA("Weld") and b.Part1 ~= nil then
				b.Part0 = b.Parent
				if clone:FindFirstChild(b.Part1.Name) then
					b.Part1 = clone[b.Part1.Name]
				elseif not specialChar then
					b:Destroy()
				end
			end
		end

		clone.Parent = workspace

		--Animations
		local tracks = {}
		local desc = humanoid:GetAppliedDescription()
		local animate = clone:FindFirstChild("Animate")
		if animate then
			for i,v in pairs(clone.Animate:GetChildren()) do
				local anim = (v:GetChildren()[1])
				if anim then
					tracks[v.Name] = cloneHumanoid:LoadAnimation(anim)
				end
			end
			tracks.idle:Play()
		end

		return clone, tracks
		
	end
end

local clone = function(plr)
	local hrp = character:FindFirstChild("HumanoidRootPart")
	if hrp then
		local clone = createClone(character)
		local humanoid = clone:WaitForChild("Humanoid")
		humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Subject
		humanoid.HealthDisplayDistance = 25
		humanoid.NameDisplayDistance = 25
		humanoid.DisplayName = " "
		local cloneHrp = clone:WaitForChild("HumanoidRootPart")
		cloneHrp.CFrame = hrp.CFrame * CFrame.new(0, 5, 0)
		clone.Parent = container
		clone.Name = " "
	end
end

game.ReplicatedStorage.CloneEvent.OnClientEvent:Connect(function(rigType)
	clone(rigType)
end)

I wonder if the

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

could be grabbing the normal character instead of the new bloxikin template?

You might be able to clone the custom bloxkin rig and replace the clone variable with that, use :ApplyDescription and then see if it works

local createClone = function(character)
	local humanoid = character:FindFirstChild("Humanoid")
	local description = humanoid:GetAppliedDescription()
	if humanoid then

		--Setup clone
		character.Archivable = true
		local clone = character:Clone()
		local cloneHumanoid = clone.Humanoid
		clone.Name = " "
		local specialChar = false
		if clone:FindFirstChild("Chest") then
			specialChar = true
		end
		for a,b in pairs(clone:GetDescendants()) do
			if b:IsA("Humanoid") then
				b.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
			elseif b:IsA("BillboardGui") then
				b:Destroy()
			elseif b:IsA("Weld") and b.Part1 ~= nil then
				b.Part0 = b.Parent
				if clone:FindFirstChild(b.Part1.Name) then
					b.Part1 = clone[b.Part1.Name]
				elseif not specialChar then
					b:Destroy()
				end
			end
		end

		clone.Parent = workspace
		cloneHumanoid:ApplyDescription(description)

		--Animations
		local tracks = {}
		local desc = humanoid:GetAppliedDescription()
		local animate = clone:FindFirstChild("Animate")
		if animate then
			for i,v in pairs(clone.Animate:GetChildren()) do
				local anim = (v:GetChildren()[1])
				if anim then
					tracks[v.Name] = cloneHumanoid:LoadAnimation(anim)
				end
			end
			tracks.idle:Play()
		end

		return clone, tracks
		
	end
end

Kinda confused on how to use ApplyDescription? I used it here but nothing changed…