Morph Script not working

Hi! I’m trying to make a Morph script but for some reason everything I try does not work because I have to destroy the Character’s parts but then the player dies. My script:

local function replaceChar(char)
	for i,v in next, char:GetChildren() do
		if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" and v.Name ~= "Humanoid" then
			--Replace it 
			local newPart = game.ReplicatedStorage.AlreadyPro[v.Name]
			local clone = newPart:Clone()
			clone.Parent = v.Parent
			v:Destroy()
		end
	end
end

local function onTouched(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		local char = hum.Parent
		replaceChar(char)
	end
end

workspace.Part.Touched:Connect(onTouched)
1 Like

Any ideas on how I could avoid making the player die?

1 Like

The head and torso are parts, that make you die upon deleting the part. I suggest making the head and torso transparent.

3 Likes

You can alternatively just Clone the morph and set the Players Character to the Morph.

Heres an example:

script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		
		if Player then		
			local NewCharacter = game.ServerStorage.Dummy:Clone()
			NewCharacter.Name = Player.Name
			Player.Character = NewCharacter
			NewCharacter.Parent = game.Workspace
		end
	end
end)```
2 Likes

If you set the character to a different character, then the camera subject is not the different character. I think.

It actually is, it worked. Also the animations were not playing but I made it so it copies Roblox’s StarterAnimation and StarterHealth scripts inside of the Character.
It works fine.

1 Like