Cloning the Character

So basically I want to make the character be cloned when they press a TextButton and the actual character would become invisible to people who do not have a certain value and also an ObjectValue would be added to the clone and the name wouldn’t display on the clone and it cannot be moved. When I attempt to do this it fails and gives me an error in output and I really need this to be fixed and I’ve tried to fix it but it won’t work.

This is the code;

local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
local Humanoid = Character:WaitForChild("Humanoid")
local SpiritualPlane = Lighting.SpiritualPlane
local Atmosphere = SpiritualPlane.Atmosphere
local Background = SpiritualPlane.Background

local MainGUI = LocalPlayer.PlayerGui.Death
local Frame = MainGUI.UI
local RemainButton = Frame.Spirit

RemainButton.MouseButton1Down:Connect(function()
	local Corpse = Character:Clone()
	Corpse.Parent = workspace
	Corpse.Humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
	Corpse.Name = Character.Name.."'s Corpse"
	local Value = Instance.new("ObjectValue",Corpse)
	Value.Name = "Corpse"
	Corpse.UpperTorso.CFrame = Character.UpperTorso.CFrame
	wait(0.1)
    local AtmosphereClone = Atmosphere:Clone()
    local BackgroundClone = Background:Clone()
    AtmosphereClone.Parent = Lighting
    BackgroundClone.Parent = Lighting
	local GhostValue = Instance.new("IntValue",Character)
	GhostValue.Name = 'Ghost'
	for i,part in pairs(NewCharacter:GetDescendants()) do
		if part:IsA("Part") or part:IsA("MeshPart") or part:IsA("Decal") or part:IsA("UnionOperation") or part:IsA("BasePart") then
			part.Transparency = 1
		end
	end
end)

Also here is the output error;

2 Likes