How to change the character of the player when they touch a part and weld their character to the new one

Hey guys,
So I was trying to change the player’s character when they touch a part. It works good for some seconds the player dies for some reason and on spawn they go back to there normal character. I don’t know how to fix it. The character I want them to change too is also rigged, if I go in the animation editor and hover over it I see the blue box around it. I can even animate it, so I think riggin shouldn’t be the problem here.
Script inside the part to be touched:

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		script.Parent.PlayerWeld.Part1 = hit.Parent.HumanoidRootPart
		game.Players:GetPlayerFromCharacter(hit.Parent).Character = script.Parent.Parent
		repeat wait()
			workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		until workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable
		workspace.CurrentCamera.CameraSubject = script.Parent.Parent
		repeat wait()
			workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		until workspace.CurrentCamera.CameraType == Enum.CameraType.Custom
	end
end)
1 Like

What exactly are you trying to do?

1 Like

hmm i did it so that am able to set the camerasubject to the new character, as far as ik u need to change it to scriptable to change the camerasubject dont u?

I don’t understand why you need the repeat loop.

plus

you are setting the camera back to normal anyways.

To change the character is actually pretty easy.
First you need to clone the scripts and localscripts that are running in the character.
Then you need to set the Player.Character property to the character you want to move via the server.
Then move the cloned scripts into the new Player.Charater

1 Like

Its a server script inside the character. And there are no other scripts in the character except this one

The problem is that after I change the character, it even changes, but the red death effect comes and the death sound plays and the player respawns in their own character afterwards. I just want to prevent this “death”.