Deleting A Player Clone

  1. What do you want to achieve?

A Way to delete a player clone, that they created using /clone.

Alternative : delete a player clone using click detector, or when a player resets.

  1. What is the issue?

ClickDetector is not working, and the clone is not deleting.

  1. What solutions have you tried so far?

The solutions I’ve tried with this is >

  1. Creating A Click Detector manually in the local function, and making a function that checks if they click detector gets clicked. If so it deletes the clone.

ClickDetector = Instance.new("ClickDetector", clone)

  1. Creating A Click Detector and a script with it. Cloning it in the function, and setting the parent to the clone.

image

The problems im having is that for 1 it basically allows the player to delete the first clone and only that clone. Im guessing because the local function gets called one time everytime you do /clone.
Im trying to figure out how to delete a “model” I guess you could say by a click detector. Also had no idea how to delete the clones if a player resets? How could I achieve any of these?

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local container = workspace
local clone
local ClickDetector = script.ClickDetector:Clone()

local createClone = function(character)
	local humanoid = character:FindFirstChild("Humanoid")
	local description = humanoid:GetAppliedDescription()
	if humanoid then
		--Setup clone
		character.Archivable = true
		clone = character:Clone()
		local cloneHumanoid = clone.Humanoid
		clone.Name = " "
		local specialChar = false
		if clone:FindFirstChild("Chest") then
			specialChar = true
		end
		for a,b in pairs(clone:GetDescendants()) do
			if b:IsA("Humanoid") then
				b.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
			elseif b:IsA("BillboardGui") then
				b:Destroy()
			elseif b:IsA("Weld") and b.Part1 ~= nil then
				b.Part0 = b.Parent
				if clone:FindFirstChild(b.Part1.Name) then
					b.Part1 = clone[b.Part1.Name]
				elseif not specialChar then
					b:Destroy()
				end
			end
		end

		clone.Parent = workspace
		cloneHumanoid:ApplyDescription(description)
		ClickDetector.Parent = clone

		--Animations
		
		local animator = humanoid:FindFirstChild("Animator")
		local animator2 = cloneHumanoid:FindFirstChild("Animator")
		
		if animator and animator2 then
			
			for _, v in pairs(animator:GetPlayingAnimationTracks()) do
				local track = animator2:LoadAnimation(v.Animation)
				track.Priority = Enum.AnimationPriority.Action
				track:Play()
				track.TimePosition = v.TimePosition
				track:AdjustSpeed(v.Speed)
			end
			
		end
		
		
	end
end

local clone = function(plr)
	local hrp = character:FindFirstChild("HumanoidRootPart")
	if hrp then
		local clone = createClone(character)
		local humanoid = clone:FindFirstChild("Humanoid")
		humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Subject
		humanoid.HealthDisplayDistance = 25
		humanoid.NameDisplayDistance = 25
		humanoid.DisplayName = " "
		local cloneHrp = clone:FindFirstChild("HumanoidRootPart")
		cloneHrp.CFrame = hrp.CFrame * CFrame.new(0, 5, 0)
		clone.Parent = container
		clone.Name = " "
	end
end

game.ReplicatedStorage.EVENTS.CloneEvent.OnClientEvent:Connect(function(rigType)
	clone(rigType)
end)

Note : this topic was part of my clone command. ( people can clone any model )

for player resetting, you already have the character, so get the humanoid, and use a Humanoid.Died:Connect to delete the clone if it exists.

for clickdetector, check when they click, using the Click event connection and delete the clone if it exists.

if players are able to make more than 1 clone, i would suggest storing the clones in a table, so you can easily access them.

1 Like

I like the idea of,

  1. Storing the clone into a table and putting it into workspace when /clone
  2. Checking to see if the player Humanoid.Died
  3. If humanoid dies, then Destroy() all the clones that are in the table/workspace

Im not very certain on what im inserting into the table, and how to check in workspace if anything in the table is there.

local clones = {}

table.insert()

I only know the basics, what would be the best way?

Try parenting the click detector to the humanoidrootpart or torso

1 Like