Why is my morph script not morphing the player

when i clicked the model that i want to morph, the player character gone and stuck being a ghost. Help me pls

local player = game:GetService("Players")

local replicatedStorage = game:GetService("ReplicatedStorage")
local collectionService = game:GetService("CollectionService")
local SmokeEmitter = require(script.Parent.SmokeEmitter)

local MorphRemoteEvent = replicatedStorage:WaitForChild("MorphRemoteEvent")

player.PlayerAdded:Connect(function(plr)
	local objectValue = Instance.new("StringValue", plr)
	objectValue.Name = "Morph"
	objectValue.Value = "Default"
end)

function objectTomorphable(object)
	if not object:FindFirstChild("Humanoid") then
		local humanoid = Instance.new("Humanoid", object)
	else
		return
	end
	
	if not object:FindFirstChild("HumanoidRootPart") then
		local primaryPart = Instance.new("Part", object)
		primaryPart.Name = "HumanoidRootPart"
		primaryPart.Size = Vector3.new(0.5,0.5,0.5)
		primaryPart.CFrame = object:GetModelCFrame()
		primaryPart.CanCollide = false
		primaryPart.Transparency = 1
		object.PrimaryPart = primaryPart
	else
		return
	end
	
	for i, v in pairs(object:GetChildren()) do
		if v:IsA("BasePart") then 
			local hasWeld = false
			for _, descendant in pairs(v:GetDescendants()) do
				if descendant:IsA("WeldConstraint") then
					hasWeld = true
					break
				end
			end

			if not hasWeld then
				local weld = Instance.new("WeldConstraint")
				weld.Part0 = v
				weld.Part1 = object:WaitForChild("HumanoidRootPart")
				weld.Parent = v
			end
			
			v.Anchored = false
		end
	end
end

MorphRemoteEvent.OnServerEvent:Connect(function(player, target)
	if collectionService:HasTag(target, "Morphable") then
		local cloneMorph = target.Parent:Clone()
		objectTomorphable(cloneMorph)
		cloneMorph.Name = player.Name
		player.Character = cloneMorph
	end
end)
1 Like
local player = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local collectionService = game:GetService("CollectionService")
local MorphRemoteEvent = replicatedStorage:WaitForChild("MorphRemoteEvent")

local function objectTomorphable(object)
    if not object:FindFirstChild("Humanoid") then
        local humanoid = Instance.new("Humanoid", object)
    end

    if not object:FindFirstChild("HumanoidRootPart") then
        local primaryPart = Instance.new("Part", object)
        primaryPart.Name = "HumanoidRootPart"
        primaryPart.Size = Vector3.new(0.5, 0.5, 0.5)
        primaryPart.CFrame = object:GetModelCFrame()
        primaryPart.CanCollide = false
        primaryPart.Transparency = 1
        object.PrimaryPart = primaryPart
    end

    for i, v in pairs(object:GetChildren()) do
        if v:IsA("BasePart") then
            local hasWeld = false
            for _, descendant in pairs(v:GetDescendants()) do
                if descendant:IsA("WeldConstraint") then
                    hasWeld = true
                    break
                end
            end

            if not hasWeld then
                local weld = Instance.new("WeldConstraint")
                weld.Part0 = v
                weld.Part1 = object:WaitForChild("HumanoidRootPart")
                weld.Parent = v
            end

            v.Anchored = false
        end
    end
end

MorphRemoteEvent.OnServerEvent:Connect(function(player, target)
    if collectionService:HasTag(target, "Morphable") then
        local cloneMorph = target.Parent:Clone()
        objectTomorphable(cloneMorph)
        cloneMorph.Name = player.Name
        
        if player.Character then
            player.Character:Destroy()
        end

        player.Character = cloneMorph
        player:LoadCharacter()
    end
end)

Try changing to this

1 Like

it didn’t work. When i click it, it just delete my character and few seconds later reset me again to my avatar.

1 Like
local player = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local collectionService = game:GetService("CollectionService")
local MorphRemoteEvent = replicatedStorage:WaitForChild("MorphRemoteEvent")

local function objectTomorphable(object)
    if not object:FindFirstChild("Humanoid") then
        local humanoid = Instance.new("Humanoid", object)
    end

    if not object:FindFirstChild("HumanoidRootPart") then
        local primaryPart = Instance.new("Part", object)
        primaryPart.Name = "HumanoidRootPart"
        primaryPart.Size = Vector3.new(0.5, 0.5, 0.5)
        primaryPart.CFrame = object:GetModelCFrame()
        primaryPart.CanCollide = false
        primaryPart.Transparency = 1
        object.PrimaryPart = primaryPart
    end

    for _, v in pairs(object:GetChildren()) do
        if v:IsA("BasePart") then
            local hasWeld = false
            for _, descendant in pairs(v:GetDescendants()) do
                if descendant:IsA("WeldConstraint") then
                    hasWeld = true
                    break
                end
            end

            if not hasWeld then
                local weld = Instance.new("WeldConstraint")
                weld.Part0 = v
                weld.Part1 = object:WaitForChild("HumanoidRootPart")
                weld.Parent = v
            end

            v.Anchored = false
        end
    end
end

MorphRemoteEvent.OnServerEvent:Connect(function(player, target)
    if collectionService:HasTag(target, "Morphable") then
        local cloneMorph = target.Parent:Clone()
        objectTomorphable(cloneMorph)
        cloneMorph.Name = player.Name

        if player.Character then
            player.Character:Destroy()
        end

        local humanoid = cloneMorph:WaitForChild("Humanoid")
        local humanoidRootPart = cloneMorph:WaitForChild("HumanoidRootPart")

        player.Character = cloneMorph
        player:LoadCharacter()

        cloneMorph:SetPrimaryPartCFrame(humanoidRootPart.CFrame)
    end
end)
1 Like

maybe calling player:LoadCharacter()` after setting player.Character won’t work ?player:LoadCharacter() can cause the player to respawn the default character. This will undo any changes you made to the player character…

1 Like

This is true, when you set the character you shouldn’t load the character again, this will undo your changes, I also noticed that you destroy the character.

MorphRemoteEvent.OnServerEvent:Connect(function(player, target)
    if collectionService:HasTag(target, "Morphable") then
        local cloneMorph = target.Parent:Clone()
        objectTomorphable(cloneMorph)
        cloneMorph.Name = player.Name

        local humanoid = cloneMorph:WaitForChild("Humanoid")
        local humanoidRootPart = cloneMorph:WaitForChild("HumanoidRootPart")

        player.Character = cloneMorph

        cloneMorph:SetPrimaryPartCFrame(humanoidRootPart.CFrame)
    end
end)
1 Like

i tried it and it delete the character. But it didn’t reset me, that’s good…

1 Like

I updated my reply check it again.

2 Likes

well , it didn’t work . But atleast i got inspiration. I fixed it :

MorphRemoteEvent.OnServerEvent:Connect(function(player, target)
	if collectionService:HasTag(target, "Morphable") then
		local cloneMorph = target.Parent:Clone()
		objectTomorphable(cloneMorph)
		cloneMorph.Name = player.Name

		cloneMorph.Parent = workspace
		cloneMorph:SetPrimaryPartCFrame(player.Character.PrimaryPart.CFrame)
		
		if player.Character then
			player.Character:Destroy()
		end

		player.Character = cloneMorph

		local camera = game:GetService("Workspace").CurrentCamera
        camera.CameraSubject = cloneMorph:WaitForChild("Humanoid")
	end
end)
1 Like

except the cameras , im still working on it. Is wonky

2 Likes

well there still 1 problem, the camera won’t follow the character ._. .

1 Like

Fire a remote event to the player and on local script change the camera type and subject:

worldCamera.CameraType = Enum.CameraType.Custom
worldCamera.CameraSubject = workspace:WaitForChild(game.Players.LocalPlayer.Name).Humanoid
2 Likes

thannkk you , it works now…sdgdhg

2 Likes