Morph system not working properly

What I want to achieve is basically a GUI where the player would have a variety of characters to choose from and then spawn into the game morphed as the character they chose. They first press the character they want to select, which then displays an information GUI about the character and if they decide to proceed they press ‘Choose’ and the GUI disappears. They then have to press on deploy to spawn in.

The base morphing system is working well, except for the fact that when the player dies or resets they don’t respawn. I’m getting this error with the morphed character only. It works perfectly when I try it with my default character.

Another major problem I have is that the character selection GUI disappears as soon as they morph into the new character. I want the GUI to stay visible until the player presses ‘Deploy’. I tried to fix this by first changing the morphing system, where the player doesn’t morph until they press deploy, and I also used a for loop to duplicate all screen GUIs inside starterGUI into the player’s local playerGUI. This didn’t work as after the player presses on ‘Deploy’ the main menu and character selection screens appear again, which I do not want.
I tried using a remote event to disable the main menu and character selection GUIs after the player presses deploy but it just further ruined the problem and didn’t work.

This is the morphing system script, placed inside the Character Selection frame.

local player = game.Players.LocalPlayer
local char = player.Character

local frame = script.Parent

-- PAGE ONE
local but1 = frame:WaitForChild('CharSelectButton1')
local but2 = frame:WaitForChild('CharSelectButton2')
local but3 = frame:WaitForChild('CharSelectButton3')
local but4 = frame:WaitForChild('CharSelectButton4')
local but5 = frame:WaitForChild('CharSelectButton5')
local but6 = frame:WaitForChild('CharSelectButton6')

-- FUNCTION FOR ALL MORPHS
local function SwitchMorph(morph)
	local newChar = morph:Clone()
	local oldChar = char
	
	local oldRootPart = oldChar:WaitForChild('HumanoidRootPart')
	local newRootPart = newChar:WaitForChild('HumanoidRootPart')
	
	newRootPart.CFrame = oldRootPart.CFrame
	newChar.Name = player.Name
	
	--newChar.Parent = workspace
	player.Character = newChar
	newChar.Parent = workspace
	
	local children = game.StarterGui:GetChildren()
	for i = 1, #children do
		local childCurrent = children[i]:Clone()
		childCurrent.Parent = player.PlayerGui
	end
	
	workspace.CurrentCamera.CameraSubject = newChar:WaitForChild('Humanoid') -- Switches the camera into the new character
	oldChar:Destroy() -- destroys the old character
end

-- CALLING FUNCTION FOR EACH BUTTON
--but1.MouseButton1Click:Connect(function()
	--SwitchMorph(game.Workspace:WaitForChild('StarterCharacter'))
--end)

-- NEW SYSTEM ~ THIS JUST MAKES IT SO THAT THE CHARACTER INFO IS DISPLAYED FIRST AND YOU HAVE TO PRESS THE DEPLOY BUTTON

but1.MouseButton1Click:Connect(function()
	local info = script.Parent:WaitForChild('InfoTab')
	local but = info:WaitForChild('choose')
	
	local deploy = script.Parent:WaitForChild('DeployButton')
	
	info.Visible = true
	
	but.MouseButton1Click:Connect(function()
		info.Visible = false
		
		deploy.MouseButton1Click:Connect(function()
			SwitchMorph(game.Workspace:WaitForChild('StarterCharacter'))
		end)
		
	end)
end)

This is the deploy button, placed inside the main menu frame.

local button = script.Parent
local frame = script.Parent.Parent

local transition = script.Parent.Parent.Parent.Parent:WaitForChild('Transition'):WaitForChild('Frame')


local tweenService = game:GetService('TweenService')


local tweenInfo1 = TweenInfo.new(
	0.5, -- no. of seconds
	Enum.EasingStyle.Linear, -- how it moves
	Enum.EasingDirection.Out, --how it moves
	0, -- how many times it repeats
	false, --go back to start after ending?
	0 -- the wait before starting
)

local properties1 = {
	['Transparency'] = 0
}

local tween1 = tweenService:Create(transition, tweenInfo1, properties1)



local tweenInfo2 = TweenInfo.new(
	0.5, -- no. of seconds
	Enum.EasingStyle.Linear, -- how it moves
	Enum.EasingDirection.Out, --how it moves
	0, -- how many times it repeats
	false, --go back to start after ending?
	0 -- the wait before starting
)


local properties2 ={
	['Transparency'] = 1
}

local tween2  = tweenService:Create(transition, tweenInfo2, properties2)


local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild('Humanoid')
local rootPart = char:WaitForChild('HumanoidRootPart')

local randomNum = math.random(1,4)

local SpawnFolder = game.Workspace:WaitForChild('SpawnPoints')
local spawnOne = SpawnFolder:WaitForChild('SpawnLocationOne')
local spawnTwo = SpawnFolder:WaitForChild('SpawnLocationTwo')
local spawnThree = SpawnFolder:WaitForChild('SpawnLocationThree')
local spawnFour = SpawnFolder:WaitForChild('SpawnLocationFour')


local debris = game:GetService('Debris')

local function shield()
	local FF = Instance.new('ForceField')	
	FF.Parent = char
	debris:AddItem(FF, 3)
	
end

button.MouseButton1Up:Connect(function()
	wait(0.1)
	
	tween1:Play()
	wait(0.9)
	tween2:Play()
	
	shield()
	
	if randomNum == 1  then
		rootPart.CFrame = spawnOne.CFrame
	elseif randomNum == 2 then
		rootPart.CFrame = spawnTwo.CFrame
	elseif randomNum == 3 then
		rootPart.CFrame = spawnThree.CFrame
	elseif  randomNum == 4 then
		rootPart.CFrame = spawnFour.CFrame 
	end
	
	
	
	frame.Visible = false
end)

Keep in mind that I also want to implement the code inside the deploy script to the morphed character. Right now it isn’t being implemented on the morphed character. Things such as the force field aren’t being implemented on the morphed character while when I spawn in my normal character it gets implemented.

This is how my code is organized in studio.
organisation

I’ve tried everything but can’t seem to solve it. Someone please come up with a solution because my head is about to blow up.

1 Like

Nevermind, I figured it out.
I completely revamped the system. I made it so that the morph script doesn’t actually morph, it just changes the name of a frame to the name of the character the player wants to morph into, and then all the magic happens in the deploy button script.
For anyone interested, here is both scripts:

Morph script:

local player = game.Players.LocalPlayer
local char = player.Character

local frame = script.Parent

-- PAGE ONE
local but1 = frame:WaitForChild('CharSelectButton1')
local but2 = frame:WaitForChild('CharSelectButton2')
local but3 = frame:WaitForChild('CharSelectButton3')
local but4 = frame:WaitForChild('CharSelectButton4')
local but5 = frame:WaitForChild('CharSelectButton5')
local but6 = frame:WaitForChild('CharSelectButton6')

local ID = game.StarterPlayer:WaitForChild('MORPH')

but1.MouseButton1Click:Connect(function()
	ID.Name = 'BONNIE'
	print(ID)
end)

but2.MouseButton1Click:Connect(function()
	ID.Name = 'MARVELGIRL'
	print(ID)
end)

Deploy script:

local button = script.Parent
local frame = script.Parent.Parent

local tweenService = game:GetService('TweenService')

local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild('Humanoid')
local rootPart = char:WaitForChild('HumanoidRootPart')

local randomNum = math.random(1,4)

local SpawnFolder = game.Workspace:WaitForChild('SpawnPoints')
local spawnOne = SpawnFolder:WaitForChild('SpawnLocationOne')
local spawnTwo = SpawnFolder:WaitForChild('SpawnLocationTwo')
local spawnThree = SpawnFolder:WaitForChild('SpawnLocationThree')
local spawnFour = SpawnFolder:WaitForChild('SpawnLocationFour')


-- FUNCTION FOR ALL MORPHS
local function switchMorph(morph)
	local newChar = morph:Clone()
	local oldChar = char
	
	local oldRootPart = oldChar:WaitForChild('HumanoidRootPart')
	local newRootPart = newChar:WaitForChild('HumanoidRootPart')
	
	newRootPart.CFrame = oldRootPart.CFrame
	newChar.Name = player.Name
	
	player.Character = newChar
	newChar.Parent = workspace
	
--	local children = game.StarterGui:GetChildren()
--	for i = 1, #children do
--		local childCurrent = children[i]:Clone()
--		childCurrent.Parent = player.PlayerGui
--	end

	local starterGUI = game.StarterGui
	local playerInfoClone = starterGUI:WaitForChild('PlayerInfo'):Clone()
	local charSelect = starterGUI:WaitForChild('CharacterSelection'):Clone()

	playerInfoClone.Parent = player.PlayerGui
	charSelect:WaitForChild('Frame').Visible = false
	charSelect.Parent = player.PlayerGui


	local transitionUI = Instance.new('ScreenGui')
	local transition = Instance.new('Frame')
	transitionUI.Parent = player.PlayerGui
	transition.Parent = transitionUI
	transition.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
	transition.Size = UDim2.new(1,0, 1,0)
	transition.Transparency = 1
	transitionUI.IgnoreGuiInset = true
	transitionUI.DisplayOrder = 10
	
	workspace.CurrentCamera.CameraSubject = newChar:WaitForChild('Humanoid')
	oldChar:Destroy()
	
	-----------------------------------------------------


	local tweeninfo1 = TweenInfo.new(
		0.5, -- no. of seconds
		Enum.EasingStyle.Linear, -- how it moves
		Enum.EasingDirection.Out, --how it moves
		0, -- how many times it repeats
		false, --go back to start after ending?
		0 -- the wait before starting
	)

	local properties1 = {
		['Transparency'] = 0
	}

	local tweeninfo2 = TweenInfo.new(
		0.5, -- no. of seconds
		Enum.EasingStyle.Linear, -- how it moves
		Enum.EasingDirection.Out, --how it moves
		0, -- how many times it repeats
		false, --go back to start after ending?
		0 -- the wait before starting
	)

	local properties2 = {
		['Transparency'] = 1
	}



	local tween1 = tweenService:Create(transition, tweeninfo1, properties1)
	local tween2 = tweenService:Create(transition, tweeninfo2, properties2)

	charSelect:WaitForChild('Frame').Visible = true
	tween1:Play()
	task.wait(0.9)
	charSelect:WaitForChild('Frame').Visible = false
	tween2:Play()


	-----------------------------------------------------
	
end



local ID = game.StarterPlayer:WaitForChild('MORPH') 
local starterPlayerFile = game.StarterPlayer


local debris = game:GetService('Debris')

local function shield()
	local FF = Instance.new('ForceField')	
	FF.Parent = char
	debris:AddItem(FF, 3)
end


button.MouseButton1Click:Connect(function()
	local descendants = starterPlayerFile:GetChildren()

	for i = 1, #descendants do
		if descendants[i].Name == 'BONNIE' then
			switchMorph(game.Workspace:WaitForChild('StarterCharacter'))
		elseif descendants[i].Name == 'MARVELGIRL' then
			switchMorph(game.Workspace:WaitForChild('MarvelGirl'))
		end
	end

	shield()

	if randomNum == 1  then
		rootPart.CFrame = spawnOne.CFrame
	elseif randomNum == 2 then
		rootPart.CFrame = spawnTwo.CFrame
	elseif randomNum == 3 then
		rootPart.CFrame = spawnThree.CFrame
	elseif  randomNum == 4 then
		rootPart.CFrame = spawnFour.CFrame 
	end

	frame.Visible = false
end)
1 Like

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