Morph kills the player's character

I made this morph system but it kills the player’s character instead of changing them to the morph.

Code:

function Morphs:ApplyMorph(morphName: string, target: Player)
	local morph = MorphsFolder:FindFirstChild(morphName)
	if not morph then
		warn(`Morph not found: {morphName}`)
		return
	end

	local character = target.Character
	if not character then
		warn(`Target {target.Name} does not have a character.`)
		return
	end

	local head = character:FindFirstChild("Head")
	if not head then
		warn(`Character {target.Name} is missing a head.`)
		return
	end

	local clonedProfile = head:FindFirstChild(`${target.Name}'s Overhead`)
	if clonedProfile then
		clonedProfile = clonedProfile:Clone()
	end

	for _,part in next,character:GetChildren() do
		if part:IsA("Part") then
			part:Destroy()
			
		end
	end
	
	morph:Clone().Parent = character

	task.wait(0.1)

	if character:FindFirstChild("Head") and clonedProfile then
		clonedProfile.Parent = character.Head
	end
end

Explorer:

image

IIRC, the proper way of doing it is to teleport the morph to the player’s current CFrame, then do
Player.Character = MORPH.

You should store the player’s old character to a variable so you can delete it.

1 Like

It deletes the player’s character

function Morphs:ApplyMorph(morphName: string, target: Player)
	local morph = MorphsFolder:FindFirstChild(morphName)
	if not morph then
		warn(`Morph not found: {morphName}`)
		return
	end

	local character = target.Character
	if not character then
		warn(`Target {target.Name} does not have a character.`)
		return
	end

	local head = character:FindFirstChild("Head")
	if not head then
		warn(`Character {target.Name} is missing a head.`)
		return
	end

	local clonedProfile = head:FindFirstChild(`${target.Name}'s Overhead`)
	if clonedProfile then
		clonedProfile = clonedProfile:Clone()
	end

	

	local morphClone = morph:Clone()
	
	if morphClone:IsA("Model") then
		morphClone:MoveTo(target.Character:WaitForChild("HumanoidRootPart").Position)
		target.Character = morphClone
		character:Destroy()
	end

	task.wait(0.1)

	if character:FindFirstChild("Head") and clonedProfile then
		clonedProfile.Parent = character.Head
	end
end