ClonedCharacter breaks after the player respawns

Been working on my customization GUI and I realized there’s a bug when a player tries to go back on it after they respawn. Their ClonedCharacter appears dead when they open the menu back up again.

Here’s what it looks like when you open the menu when you first join the game:
image
And here’s what it looks like after I respawn and open the menu again:

I have RestOnSpawn set to false for when I do I can’t even open the menu back after the player respawns.

I don’t wish to show the full playUI script but here’s what I have for when a player opens the menu.

--CharacterMenuTween

local Camera = workspace.CurrentCamera

repeat
	print("character not yet defined")
	wait(0.5)
until Player.Character ~= nil

local Character = Player.Character or Player.CharacterAdded:wait()
local TeleportTo = workspace.TeleportTo
local ClonedCharacter = Character:Clone()


Character.Archivable = true
CustomizeButton.MouseButton1Click:Connect(function() -- Menu Opens
Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	if ClonedCharacter == nil then
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = workspace.CamPart.CFrame
		CharacterMenu:TweenPosition(UDim2.new(0.125, 0, 0.5, 0), "Out", "Sine", 1, false)
		SettingsMenu:TweenPosition(UDim2.new(-0.75, 0, 0.455, 0), "Out", "Sine", 1, false)
		ClonedCharacter = Character:Clone()
		ClonedCharacter.Parent = workspace
		ClonedCharacter:SetPrimaryPartCFrame(TeleportTo.CFrame * CFrame.new(Vector3.new(0, 4, 0)))
		ClonedCharacter.Humanoid:UnequipTools()
		if ClonedCharacter.PrimaryPart.CFrame == TeleportTo.CFrame then
			ClonedCharacter.Head.Anchored = true
			ClonedCharacter["Left Arm"].Anchored = true
			ClonedCharacter["Left Leg"].Anchored = true
			ClonedCharacter["Right Arm"].Anchored = true
			ClonedCharacter["Right Leg"].Anchored = true
			ClonedCharacter.Torso.Anchored = true
		end
		while ClonedCharacter:FindFirstChild("IronHelm") do
			ClonedCharacter.IronHelm:Destroy()
			wait()
		end
		while ClonedCharacter:FindFirstChild("IronChestClone") do
			ClonedCharacter.IronChestClone:Destroy()
			ClonedCharacter.IronLeftShoulderClone:Destroy()
			ClonedCharacter.IronRighShoulder:Destroy()
			wait()
		end
		while ClonedCharacter:FindFirstChild("VikingHat") do
			ClonedCharacter.VikingHat.Handle.Transparency = 0 
			wait()
		end
		while ClonedCharacter:FindFirstChild("PirateHat") do
			ClonedCharacter.PirateHat.Handle.Transparency = 0 
			wait()
		end
		while ClonedCharacter:FindFirstChild("WizardHat") do
			ClonedCharacter.WizardHat.Handle.Transparency = 0 
			wait()
		end
	end
end)

SettingsCloseC.MouseButton1Click:Connect(function()-- Menu Closes
	if ClonedCharacter ~= nil then
		workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character
		workspace.CurrentCamera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame
		workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

		CharacterMenu:TweenPosition(UDim2.new(-1, 0, 0.5, 0), "Out", "Sine", 1, false)
		PantFrame:TweenPosition(UDim2.new(1.741, 0,0.177, 0), "Out", "Sine", 1, false)
		SkinTone:TweenPosition(UDim2.new(1.509, 0,0.759, 0), "Out", "Sine", 1, false)
		ShirtFrame:TweenPosition(UDim2.new(1.741, 0,0.079, 0), "Out", "Sine", 1, false)
		HatFrame:TweenPosition(UDim2.new(1.67, 0,0.181, 0), "Out", "Sine", 1, false)
		FaceFrame:TweenPosition(UDim2.new(1.67, 0,0.181, 0), "Out", "Sine", 1, false)
		ClonedCharacter:Destroy()
		ClonedCharacter = nil
	end
end)

The rest of the LocalScript seems to work just, it’s just after I respawn and try to open the menu again the ClonedCharacter is dead.

Any help will be appreciated, thanks!

Try recloning it after humanoid.Died?

That does seem to be the issue, I tried using an if statement to check if the player died before hand.

		if ClonedCharacter:WaitForChild("Humanoid").Died then
			ClonedCharacter = Character:Clone()
		end

However, the new Clone comes in and wears the dead one like a shrine

Try deleting the old Clone and replace it with new one when player respawn

Here’s the full thing we’ve managed to come up with and the ClonededCharacter is still dying.

--CharacterMenuTween

local Camera = workspace.CurrentCamera

repeat
	print("character not yet defined")
	wait(0.5)
until Player.Character ~= nil

local Character = Player.Character or Player.CharacterAdded:wait()
local TeleportTo = workspace.TeleportTo
local ClonedCharacterDiedConnection = nil


Character.Archivable = true
CustomizeButton.MouseButton1Click:Connect(function() -- Menu Opens
Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	if ClonedCharacter == nil then
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = workspace.CamPart.CFrame
		CharacterMenu:TweenPosition(UDim2.new(0.125, 0, 0.5, 0), "Out", "Sine", 1, false)
		SettingsMenu:TweenPosition(UDim2.new(-0.75, 0, 0.455, 0), "Out", "Sine", 1, false)
		ClonedCharacter = Character:Clone()
		ClonedCharacter.Parent = workspace
		ClonedCharacter:SetPrimaryPartCFrame(TeleportTo.CFrame * CFrame.new(Vector3.new(0, 4, 0)))
		ClonedCharacter.Humanoid:UnequipTools()
		if ClonedCharacter.PrimaryPart.CFrame == TeleportTo.CFrame then
			ClonedCharacter.Head.Anchored = true
			ClonedCharacter["Left Arm"].Anchored = true
			ClonedCharacter["Left Leg"].Anchored = true
			ClonedCharacter["Right Arm"].Anchored = true
			ClonedCharacter["Right Leg"].Anchored = true
			ClonedCharacter.Torso.Anchored = true
		end
		while ClonedCharacter:FindFirstChild("IronHelm") do
			ClonedCharacter.IronHelm:Destroy()
			wait()
		end
		while ClonedCharacter:FindFirstChild("IronChestClone") do
			ClonedCharacter.IronChestClone:Destroy()
			ClonedCharacter.IronLeftShoulderClone:Destroy()
			ClonedCharacter.IronRighShoulder:Destroy()
			wait()
		end
		while ClonedCharacter:FindFirstChild("VikingHat") do
			ClonedCharacter.VikingHat.Handle.Transparency = 0 
			wait()
		end
		while ClonedCharacter:FindFirstChild("PirateHat") do
			ClonedCharacter.PirateHat.Handle.Transparency = 0 
			wait()
		end
		while ClonedCharacter:FindFirstChild("WizardHat") do
			ClonedCharacter.WizardHat.Handle.Transparency = 0 
			wait()
		end
		ClonedCharacterDiedConnection = ClonedCharacter.Humanoid.Died:Connect(function()
			ClonedCharacter:Destroy()
		end)  
	end
end)

SettingsCloseC.MouseButton1Click:Connect(function()-- Menu Closes
	if ClonedCharacter ~= nil then
		workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character
		workspace.CurrentCamera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame
		workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

		if typeof(ClonedCharacterDiedConnection) == "RBXScriptConnection" then
			ClonedCharacterDiedConnection:Disconnect()
		end

		CharacterMenu:TweenPosition(UDim2.new(-1, 0, 0.5, 0), "Out", "Sine", 1, false)
		PantFrame:TweenPosition(UDim2.new(1.741, 0,0.177, 0), "Out", "Sine", 1, false)
		SkinTone:TweenPosition(UDim2.new(1.509, 0,0.759, 0), "Out", "Sine", 1, false)
		ShirtFrame:TweenPosition(UDim2.new(1.741, 0,0.079, 0), "Out", "Sine", 1, false)
		HatFrame:TweenPosition(UDim2.new(1.67, 0,0.181, 0), "Out", "Sine", 1, false)
		FaceFrame:TweenPosition(UDim2.new(1.67, 0,0.181, 0), "Out", "Sine", 1, false)
		ClonedCharacter:Destroy()
		ClonedCharacter = nil
	end
end)

When the player’s character reloads delete the old character clone wait for CharacterAppearanceLoaded to fire then clone the new character and use it in the viewport.

Works now, if you define the player’s character within the MouseButton1Click function.