Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make sure a character lives while morphing

For my Bleach RPG, characters will morph into a built model upon spawning. Some of these models include having largely sized limbs and Torso's. Since I'm resizing the limbs to morph the character, each Motor in the Torso will temporarily have a Part1 of nil. In order to counter this, I first anchor the limb and then store the value of Part1 as an ObjectValue and then after it's finished resizing it will set the Part1 back to it's correct value.

My problem is, there are many cases in which the player will spawn and instantly die; probably since it cannot reconnect the limbs together quickly enough. It works fine it Play Solo, but the character only lives 2 out of 3 times in server mode.

Extra information: The welds C0 and C1 aren't defined in the morph script; there's a localscript (animation) that will be pasted into the character that sets the C0 and C1 if the Morph-To body is different from the typical Roblox body.

--userdata char - This is the player's character model.
--userdata model - This is the model that char will morph into.

--Clears character appearance
for _,v in pairs(char:GetChildren()) do --Anchor the character before resetting welds
	if v:IsA("BasePart") then
		v.Anchored = true
	end
end
for _,v in pairs(char:GetChildren()) do
	for _,x in pairs(v:GetChildren()) do
		if x:IsA("Motor6D") then
			Instance.new("ObjectValue",x).Value = x.Part1
			x.Part1 = nil
			--Stores the Part1 value inside of the player's limb weld
			--Right Shoulder would store Right Arm
			--Left Hip would store Left Leg
			--And etc.
		end
	end
end
--Changes Body Colors
for _,v in pairs(model:GetChildren()) do
	local part = char:findFirstChild(v.Name)
	--If a part in the model has the same name as a part in the character.
	--For instance, Right Arm or Torso
	if v:IsA("BasePart") and part then
		--Makes the properties of the part in the character
		--mimic the same properties of the part in the model
		part.Size = v.Size
		char:MakeJoints()
		part.TopSurface = "Smooth" --Only because I like smooth surfaces
		part.BottomSurface = "Smooth"
	elseif true then
		--Adds extra little details to the character.
		--Stuff like masks, eyes, or wings.
		--Ultimately, not the problem here.
	elseif v:IsA("LocalScript") and char:findFirstChild("DefaultAnimation") then
		--if the model contains a localscript, then we want to replace
		--the character's current animation script with this new localscript.
		char.DefaultAnimation:Destroy()
		v:clone().Parent = char
	end
end
for _,o in pairs(char:GetChildren()) do
	if o:IsA("BasePart") then
		for _,v in pairs(o:GetChildren()) do
			if (v:IsA("Weld") or v:IsA("Motor") or v:IsA("Motor6D")) and v:findFirstChild("Value") then
				local part1 = v.Value.Value
				v.Part1 = part1
				v.Part1.Anchored = false
				v.Part0.Anchored = false
				v.Part1 = part1
			end
		end
	end
end

1 answer

Try creating the new Character without resizing the current one, and then "transplanting" the humanoid into the new Character.

You can weld the new Character without it breaking, and only hopping the Humanoid over should stop it from dying.

This discussion is preserved as it was. New answers, comments, and votes are closed.