Script does not work

recently i have tried to create morphs, i made it so that they all had the same function to their own things and such, but something really strange happens

character vanishes, unable to move and stuff

this is the script

local CharacterModels = workspace:WaitForChild("CharacterModels")

local function MorphInto(Morph: Model, Player: Player)
	local oldChar = Player.Character
	if not oldChar then return end

	local oldRoot = oldChar:FindFirstChild("HumanoidRootPart")
	local oldCFrame = oldRoot and oldRoot.CFrame

	local MorphClone = Morph:Clone()
	MorphClone.Name = Player.Name
	MorphClone.Parent = workspace

	Player.Character = MorphClone

	local newRoot = MorphClone:FindFirstChild("HumanoidRootPart")
	if newRoot and oldCFrame then
		newRoot.CFrame = oldCFrame
	end
end


for _, v in ipairs(CharacterModels:GetChildren()) do
	local Morph = v:FindFirstChild("Morph")
	local torso = Morph and Morph:FindFirstChild("UpperTorso")
	local Prompt = torso and torso:FindFirstChildOfClass("ProximityPrompt")

	if Prompt then
		Prompt.Triggered:Connect(function(Player)
			MorphInto(Morph, Player)
		end)
	end
end

the morph has an animate script, humanoid, humanoidrootpart

so i dont know what is going wrong here

these are all r15)

if you see me posting twice its cause i just made this to have a better and more noticable title)

1 Like

I would really recommend using :ApplyHumanoidDescription as it will look a lot smoother and fix these issues.

example code:

humanoid:ApplyDescription(morph.Humanoid:GetAppliedDescription())

The new character does exist and you are able to move it, but the camera subject doesn’t update when the player’s character is changed outside of :LoadCharacter(). A simple fix for the camera is something like this:

--// Put in StarterPlayerScripts
local function listenForCharacterChange()
	game.Players.LocalPlayer:GetPropertyChangedSignal("Character"):Connect(function()
		local newCharacter = game.Players.LocalPlayer.Character
		if not newCharacter then
			return
		end
		
		local humanoid = newCharacter:WaitForChild("Humanoid")
		workspace.CurrentCamera.CameraSubject = humanoid
	end)
end
listenForCharacterChange()

I’m not sure why the character’s CFrame doesn’t update properly, but this will at least solve the camera issue

I have tested the OP’s script and after placing this line of code

before this line of code,

so now the code looks like this:

    local MorphClone = Morph:Clone()
	MorphClone.Name = Player.Name
	Player.Character = MorphClone
	
	MorphClone.Parent = workspace

the camera now works and is automatically focusing on the new morph model. My assumption is that because you parent the morph clone to workspace first BEFORE setting it to Player.Character, your code shows as if

TL;DR: Try setting the morph clone to Player.Character first before parenting it to workspace. Your code should work.

2 Likes

You guys are life savers, thank you

nvm i found another problem, once morphed i cant move

Is the morph character anchored?

Can you show us the current code now and a video demonstrating the problem?

the video is posted^^ but i can make another to display the current problem

i put the models and the script you guys have provided me in a different game for better testing, now its doing nothing

local CharacterModels = workspace:WaitForChild("CharacterModels")

local function MorphInto(Morph: Model, Player: Player)
	local oldChar = Player.Character
	if not oldChar then return end

	local oldRoot = oldChar:FindFirstChild("HumanoidRootPart")
	local oldCFrame = oldRoot and oldRoot.CFrame

	local MorphClone = Morph:Clone()
	MorphClone.Name = Player.Name
	Player.Character = MorphClone

	MorphClone.Parent = workspace

	local newRoot = MorphClone:FindFirstChild("HumanoidRootPart")
	if newRoot and oldCFrame then
		newRoot.CFrame = oldCFrame
	end
end


for _, v in ipairs(CharacterModels:GetChildren()) do
	local Morph = v:FindFirstChild("Morph")
	local torso = Morph and Morph:FindFirstChild("UpperTorso")
	local Prompt = torso and torso:FindFirstChildOfClass("ProximityPrompt")

	if Prompt then
		Prompt.Triggered:Connect(function(Player)
			print("Triggered")
			MorphInto(Morph, Player)
		end)
	end
end
--// Put in StarterPlayerScripts
local function listenForCharacterChange()
	game.Players.LocalPlayer:GetPropertyChangedSignal("Character"):Connect(function()
		local newCharacter = game.Players.LocalPlayer.Character
		if not newCharacter then
			return
		end
		
		local humanoid = newCharacter:WaitForChild("Humanoid")
		workspace.CurrentCamera.CameraSubject = humanoid
	end)
end
listenForCharacterChange()

the print check isnt printing either

should i perhaps just post the models here so that you guys can see it? it’ll be faster and you’ll be abl to see if something is wrong with the models rather then the script

(proximityprompt is in uppertorso)

Models.rbxm (128.7 KB)

i fixed it guys, thank you to everyone who offered help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.