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)
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)```
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.