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)
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)
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)
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…
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)
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)