How would I make an NPC mimic a player's avatar? [R6]

I’m trying to make an NPC copy a player once it kills them. I have it working, however at the moment it can take everything but packages.

I’ve looked at other topics but most involve either R15 or :Clone(), which doesn’t work in this particular case as the scripts need to remain in the same NPC to allow it to initiate chase scenes etc. This means I cannot make a new rig via cloning.

As I have it taking clothing, hats etc, I’m now looking at meshes and textures on body parts. Is there a way I could have the NPC take the meshes from a players avatar and apply them to itself? Currently I’m looking into whether every body part has a mesh instance within it, or if the body parts are mesh parts. The body parts being mesh parts would be an issue as the NPC spawns as an R6 preset, with base parts instead.

Any help would be appreciated, however if not I can always take the long route and replicate the NPC functions into the player, however I would need to figure out how to have it carry over the information from the previous scripts which would be inconvenient.

This is the current script: [not using cloning]

local rootPart = script.Parent:WaitForChild("HumanoidRootPart")
local hum = script.Parent:WaitForChild("Humanoid")

local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("Binds"):WaitForChild("Fraud")

local canChange = true

local beginRM = folder:WaitForChild("BeginChase")
local endRM = folder:WaitForChild("EndChase")

local function SetColor(input)
	for i,v in pairs(script.Parent:GetChildren()) do
		if v:IsA("BasePart") or v:IsA("UnionOperation") or v:IsA("MeshPart") and v.Name ~= "Handle" and v.Parent:FindFirstChild("Humanoid") then
			if not v:FindFirstAncestor("Handle") then
				v.Color = input
			end
		end
	end
end

local function TakeHats(characterToReplicate)
	for i,v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Accessory") then
			v:Destroy()
		end
	end
	
	for i,v in pairs(characterToReplicate:GetChildren()) do
		if v:IsA("Accessory") then
			v:Clone().Parent = script.Parent
		end
	end
end

local function TakeClothing(CTR)
	local shirtFound = false
	local pantsFound = false
	local tshirtFound = false
	
	local shirt = script.Parent:FindFirstChildOfClass("Shirt") or Instance.new("Shirt", script.Parent)
	local pants = script.Parent:FindFirstChildOfClass("Pants") or Instance.new("Pants", script.Parent)
	local tshirt = script.Parent:FindFirstChildOfClass("ShirtGraphic") or Instance.new("ShirtGraphic", script.Parent)
	
	for i,v in pairs(CTR:GetChildren()) do
		if v:IsA("Shirt") then
			shirt.ShirtTemplate = v.ShirtTemplate
			shirtFound = true
		end
	end
	
	for i,v in pairs(CTR:GetChildren()) do
		if v:IsA("Pants") then
			pants.PantsTemplate = v.PantsTemplate
			pantsFound = true
		end
	end
	
	for i,v in pairs(CTR:GetChildren()) do
		if v:IsA("ShirtGraphic") then
			tshirt.Graphic = v.Graphic
			tshirtFound = true
		end
	end
	
	if not shirtFound then
		script.Parent:FindFirstChildOfClass("Shirt"):Destroy()
	end
	
	if not pantsFound then
		script.Parent:FindFirstChildOfClass("Pants"):Destroy()
	end
	
	if not tshirtFound then
		script.Parent:FindFirstChildOfClass("ShirtGraphic"):Destroy()
	end
end

local function TakeMeshes(origin, replication)
	print("Waiting on function")
end

local function TakePackage(character)
	local rightArm = character:WaitForChild("Right Arm")
	local leftArm = character:WaitForChild("Left Arm")
	local rightLeg = character:WaitForChild("Right Leg")
	local leftLeg = character:WaitForChild("Left Leg")
	local torso = character:WaitForChild("Torso")
	local head = character:WaitForChild("Head")
	
	
end

local function Replicate(character)
	if character:FindFirstChild("Head") then
		local color = character:FindFirstChild("Head").Color
		SetColor(color)

		TakeHats(character)

		TakeClothing(character)

		local face = script.Parent.Head:WaitForChild("face") or Instance.new("Decal", script.Parent.Head)
		face.Name = "face"

		if character.Head.face then
			face.Texture = character.Head.face.Texture
		else
			face:Destroy()
		end
	end
end

rootPart.Touched:Connect(function(hit)
	if not canChange then return end
	if hit.Parent.Name == "Bob" then return end
	
	if hit:IsA("BasePart") or hit:IsA("MeshPart") or hit:IsA("UnionOperation") and hit.Name == "HumanoidRootPart" then
		if not hit.Parent:FindFirstChild("Humanoid") then return end
		Replicate(hit.Parent)
		canChange = false
		hit.Parent:FindFirstChild("Humanoid"):TakeDamage(100)
		wait(10)
		canChange = true
	end
end)

beginRM.Event:Connect(function()
	canChange = true
end)

endRM.Event:Connect(function()
	canChange = false
end)

It’s sloppy but the best I could do for now. I’m working on polishing it a bit to simply clone shirts, graphics and pants too.

1 Like

A much much simpler way to do all of this is to load the character’s avatar appearance via their humanoid description then apply it directly to the dummy.

local function Replicate(Character)
    local Humanoid = Character.Humanoid
    local Description = Humanoid:GetAppliedDescription()

    NPC.Humanoid:LoadDescription(Description)
end
6 Likes

Holy cow I did not realize it was this simple. Thank you so much!

1 Like