Cloning Character and Limb Position

Okay so I had a cool idea for a Flash game, and I wanted to clone my character and have the limbs and joints take on the position and orientation of the character at the time it was spawned, I managed to get it to do that somewhat:

https://gyazo.com/d2f8db4281d0e1cad04e9f537ccfc9ac

but my problem is the Limbs and Joints don’t take on the Position or Orientation of the Character at the time it was spawned…

here’s the code

local Effect = {}
local TweenService = game:GetService("TweenService")

local Effect = {}
local TweenService = game:GetService("TweenService")

Effect.new = function(Character)
  Effect.Character = Character
  Effect.Debris = Instance.new("Folder")
  Effect.Debris.Name = "Debris"
  Effect.Debris.Parent = Effect.Character
  Effect.Clone = nil
  Effect.IsSet = false
  return Effect 
end

function Effect:CreateClone()
 self.Character.Archivable = true
 self.Clone = self.Character:Clone()
 for i,v in pairs(self.Clone:GetChildren()) do 
      if v:IsA("Script") or v:IsA("LocalScript") then
          v:Destroy()
      end
  end
  local Limbs = self:FetchLimbs()
  self:SetLimbs(Limbs)
  self.Clone.Parent = self.Debris
  wait(2)
  self.Clone:Destroy()
end

function Effect:FetchLimbs()
 local Limbs = {}
      for i,v in pairs(self.Character:GetChildren()) do
          if v:IsA("MeshPart") then
              Limbs[v.Name] = v.Orientation
              print(v.Name)
          end
      end
  return Limbs
end

function Effect:SetLimbs(Limbs)
   for i,v in pairs(self.Clone:GetChildren()) do
       if v:IsA("MeshPart") then
           v.Orientation = Limbs[v.Name]
       end
   end
end

function Effect:Update()
  self:CreateClone()
 end

return Effect

Does anyone know how to solve this?

2 Likes

The transform property of the joints reset when the model is cloned.

Edit: I had to change a few things because of the way you had it setup before. I tried my best to not alter the structure of your script.

You could really improve the script by removing the humanoid and anchoring the root part, but I’ll leave it to you to do whatever you want to do.

https://i.gyazo.com/711f90b7ee6658295e95a61b6c9f683d.mp4

local Motor6Ds = {
	LeftUpperLeg = "LeftHip",
	LeftLowerLeg = "LeftKnee",
	RightLowerLeg = "RightKnee",
	RightUpperArm = "RightShoulder",
	RightHand = "RightWrist",
	RightLowerArm = "RightElbow",
	RightUpperLeg = "RightHip",
	UpperTorso = "Waist",
	LeftHand = "LeftWrist",
	LowerTorso = "Root",
	RightFoot = "RightAnkle",
	Head = "Neck",
	LeftUpperArm = "LeftShoulder",
	LeftFoot = "LeftAnkle",
	LeftLowerArm = "LeftElbow"
}

local Effect = {}
Effect.__index = Effect

local TweenService = game:GetService("TweenService")

function Effect.new(Character)
	local self = setmetatable({}, Effect)
	
	self.Character = Character
	self.Debris = Instance.new("Folder")
	self.Debris.Name = "Debris"
	self.Debris.Parent = self.Character
	self.Clone = nil
	self.IsSet = false
	
	return self 
end

function Effect:CreateClone()
	self.Character.Archivable = true
	self.Clone = self.Character:Clone()
	for i,v in pairs(self.Clone:GetChildren()) do 
 		if v:IsA("Script") or v:IsA("LocalScript") then
    		v:Destroy()
     	end
  	end
 	local Limbs = self:FetchLimbs()
  	self:SetLimbs(Limbs)
  	self.Clone.Parent = self.Debris
  	wait(2)
  	self.Clone:Destroy()
end

function Effect:FetchLimbs()
 	local Limbs = {}
      	for i,v in pairs(self.Character:GetChildren()) do
          	if v:IsA("MeshPart") then
              	Limbs[v.Name] = v[Motor6Ds[v.Name]].Transform
             	 print(v.Name)
          	end
      	end
  	return Limbs
end

function Effect:SetLimbs(Limbs)
   for i,v in pairs(self.Clone:GetChildren()) do
       if v:IsA("MeshPart") then
           v[Motor6Ds[v.Name]].Transform = Limbs[v.Name]
       end
   end
end

function Effect:Update()
 	self:CreateClone()
end

return Effect
5 Likes

I’ll work off of your code, I guess I was too lazy to try it thank you so much man much appreciated

where do I put the script ? I don’t really understand what to do with it :I