Part not replicating touchinterest when cloned

so i have a folder and it has parts inside. whenever u touch 1 of the parts it disappears after a short time then respawns simple enough right but when it respawns doesn’t get destroyed when u touch it

local Blocks = script.Parent

for i,v in pairs(Blocks:GetChildren()) do
	if v:IsA("Part") then
		local Bool = Instance.new("BoolValue")
		Bool.Value = false
		Bool.Name = "Bool"
		Bool.Parent = v
		
		v.Touched:Connect(function()
			if v.Bool.Value == false then
				v.Bool.Value = true
				local NewPart = v:Clone()
				NewPart.Bool.Value = false
				wait(0.75)
				v:Destroy()
				wait(5)
				NewPart.Position = v.Position 
				NewPart.Parent = Blocks
			end
		end)
	end
end

image

I believe it’s because that new part has no connections once you clone it. That .Touched only runs once, so it never gets the chance to attach to the clone.

You can make a createPart function and connect each part to a Touched event individually. This should give you more flexibility across the board.

Since you’re destroying the part before you make a new one, you should store its CFrame before the part is destroyed.

1 Like

That’s because your loop only runs once; Meaning that it only affects already existing objects and not new objects. To fix that, you can do this;

local Blocks = script.Parent

function CreateTouchedEvent(object)
	if object:IsA("Part") then
		local Bool = Instance.new("BoolValue")
		Bool.Value = false
		Bool.Name = "Bool"
		Bool.Parent = object

		object.Touched:Connect(function()
			if object.Bool.Value == false then
				object.Bool.Value = true
				local NewPart = object:Clone()
				NewPart.Bool.Value = false
				wait(0.75)
				object:Destroy()
				wait(2.5)
				NewPart.Position = object.Position 
				NewPart.Parent = Blocks
			end
		end)
	end
end

for _, object in pairs(Blocks:GetChildren()) do
	CreateTouchedEvent(object)
end


Blocks.ChildAdded:Connect(function(NewObject)
	CreateTouchedEvent(NewObject)
end)

Instead of destroying the instance, you could set the transparency to 1, CanCollide false and CanTouch false. The CanTouch property makes it so that it doesn’t detect Touched events.