Character Morph script

This script took more time to make than I care to disclose. It will replace your character with the model while preserving the scripts and the position of your character.

It’s definitely not the most sophisticated thing in the world but I thought i’d share it just because it’s nice to have the general idea.

local function transform(char,model)
	local model=model:Clone()
	model:SetPrimaryPartCFrame(char.PrimaryPart.CFrame+Vector3.new(0,model:GetExtentsSize().Y,0))
	local h=char.Humanoid
	local function unkill()
		h:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
	end
	for i,v in pairs(h:GetPlayingAnimationTracks()) do
		v:Stop()
	end
	h.Parent=game.ReplicatedStorage
	unkill()
	for i,v in pairs(char:GetChildren()) do
		if v.Name~="Humanoid" and not v:IsA("Script") and not v:IsA("LocalScript") then
			v:Destroy()
		end
	end
	local hipheight=model.Humanoid.HipHeight
	local primary=model.PrimaryPart
	for i,v in pairs(model:GetChildren()) do
		if v.Name~="Humanoid" then
			v.Parent=char
		end
	end
	-- synchronize.
	model:Destroy()
	char.PrimaryPart=char.HumanoidRootPart
	h.HipHeight=hipheight
	h.Parent=char
	char.PrimaryPart=char.HumanoidRootPart
	h.HipHeight=hipheight
    local plr=game.Players:GetPlayerFromCharacter(char)
    if plr then -- thanks roblox.
        game.ReplicatedStorage.HipHeight:FireClient(plr,hipheight)
    end
end

transform(game.Players["you"].Character,workspace.Dummy)

-- NOTE: if you are transforming a player into a model, you must also prevent their state from changing to dead on the client.
--[[ This can be accomplished in a makeshift way most by firing some sort of remote function to the player
when receiving the remote (on client), run:
spawn(function()
for i=1,120 do
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead,false)
	game:GetService("RunService").Heartbeat:wait()
end
end)
wrap it in spawn so it doesnt delay transformation.

--]]

I made this script based on this post. Are there any methods of cleanly swapping character models from default rigs to custom character constructs? - #12 by PeZsmistic

Note: this script prevents characters from dying. I don’t fully understand humanoid states so keep in mind that if you ever use this script it’ll need fixing in that area

24 Likes

Hey! I have no idea how to script but this is just what I needed for my game, how would I go about implementing it? I have a fully rigged character with animations I just need it to be able to shift to it lol, thanks in advance if you read this

2 Likes

It works perfectly, just one problem I don’t want the player’s accessories and clothing to be in the final character, I tried removing the shirt and accessories by using GetChildren() but the player’s clothing and accessories still in the final character, I did this because my custom character already has it’s own clothing and doesn’t require the player’s accessories, thanks.

1 Like

You could have named the variables better. Anyway pog

2 Likes