How would I do a morph to the player R15?

Hello, can someone help me? Im trying to make a morph when the player clicks a GUI button.
So when the player clicks the GUI button, it sends a message to the server; the local script works fine, but the server script doesn’t work for me.

ServerScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GokuMorphEvent = ReplicatedStorage.GokuMorph
local debounce = true

GokuMorphEvent.OnServerEvent:Connect(function(obj)
	local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
	if plr and plr.Character and debounce == true then
		debounce = false

		local morphedCharacterModel = ReplicatedStorage.StarterCharacter_Goku

		local charClone = morphedCharacterModel:Clone()
		charClone.Name = plr.Name
		plr.Character = charClone

		local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
		local plrRoot = obj.Parent:FindFirstChild("HumanoidRootPart") or obj.Parent:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		charClone.Parent = workspace

		wait(.5)

		debounce = true
	end
end)

any solution?

8 Likes

What is not working?

Are there any errors in the output window?

1 Like

Nope, there is no error, but the morph is not working. I want the script, when it’s activated, to copy an already defined model of a character and then replace the player character with the new one.

1 Like

Add print statements after each if statement and see if each section of your code is executing.

Okay, got it. The first if statement is not working.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GokuMorphEvent = ReplicatedStorage.GokuMorph
local debounce = true

GokuMorphEvent.OnServerEvent:Connect(function(obj)
	local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
	if plr and plr.Character and debounce == true then
		print(plr.Name)
		debounce = false

		local morphedCharacterModel = ReplicatedStorage.StarterCharacter_Goku

		local charClone = morphedCharacterModel:Clone()
		charClone.Name = plr.Name
		plr.Character = charClone

		local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
		local plrRoot = obj.Parent:FindFirstChild("HumanoidRootPart") or obj.Parent:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		charClone.Parent = workspace

		wait(.5)

		debounce = true
	end
end)

What is the problem?

What is the obj parameter you are sending from the client? Can we see your client script?

Print the obj and see what it is.

Then print the obj.Parent and see what it is also.

I don’t send anything from the Client; it’s just to get the player, like hit.parent
I guess it’s because of the if statements, one of them is not found.

The first parameter of .OnServerEvent is the client that fired the event. Try this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GokuMorphEvent = ReplicatedStorage.GokuMorph
local debounce = true

GokuMorphEvent.OnServerEvent:Connect(function(plr)
	if plr and plr.Character and debounce == true then
		debounce = false

		local morphedCharacterModel = ReplicatedStorage.StarterCharacter_Goku

		local charClone = morphedCharacterModel:Clone()
		charClone.Name = plr.Name

		local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
		local plrRoot = plr.Character:FindFirstChild("HumanoidRootPart") or plr.Character:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		charClone.Parent = workspace

        plr.Character = charClone

		task.wait(.5)

		debounce = true
	end
end)

Edit: I just realized a part of your code also uses obj. Give me a second.

1 Like

That’s what I was going to say about the obj

ServerScriptService.Morph:16: attempt to index nil with 'Parent'
1 Like

I edited the script. Try it again.

1 Like

When the script is activated, my character gets destroyed. and I return to the main menu, where the play button and settings, and other buttons. I think the morph needs to be rewritten.

and I keep getting errors now from another script:

local ShotAnim = script.FireAnim

Error:

FireAnim is not a valid member of LocalScript "Players.Koki0991.Backpack.Fists.KiBullets[X][Hold]"

do you have any solution?

1 Like

Yeah, I think this method of morphing is obsolete and doesn’t work anymore.

I’m just gonna straight-up rewrite your script:

local replicatedStorage = game:GetService("ReplicatedStorage")

local gokuMorphEvent = replicatedStorage:WaitForChild("GokuMorph")

local gokuMorph = replicatedStorage:WaitForChild("StarterCharacter_Goku")

local debounce = true

local function morph(char, morphModel)
	local model = morphModel:Clone()
	model:PivotTo(char.WorldPivot + Vector3.new(0, model:GetExtentsSize().Y, 0))
	
	local hum = char:WaitForChild("Humanoid")
	
	for _, track in ipairs(hum:GetPlayingAnimationTracks()) do
		track:Stop()
	end
	
	hum.Parent = nil
	hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
	
	for _, instance in ipairs(char:GetChildren()) do
		if not instance:IsA("Humanoid") and not instance:IsA("Script") and not instance:IsA("LocalScript") then
			instance:Destroy()
		end
	end
	
	for _, instance in ipairs(model:GetChildren()) do
		if not instance:IsA("Humanoid") and not instance:IsA("Script") and not instance:IsA("LocalScript") then
			instance.Parent = char
		end
	end
	
	hum.HipHeight = model:WaitForChild("Humanoid").HipHeight
	hum.Parent = char
	hum.HipHeight = model:WaitForChild("Humanoid").HipHeight
	
	char.PrimaryPart = char:WaitForChild("HumanoidRootPart")
end

local function onGokuMorphEvent(player)
	if debounce then
		debounce = false
		
		morph(player.Character, gokuMorph)
		
		local function debounceDelay() debounce = true end
		task.delay(0.5, debounceDelay)
	end
end

gokuMorphEvent.OnServerEvent:Connect(onGokuMorphevent)

And for the FireAnim thing, try doing:

local shotAnim = script:WaitForChild("FireAnim")

If that doesn’t work, consider renaming the script, because [] are operators in tables.

1 Like