Hit effect overlaps

local ignorelist = {"HitBox","HitBox2","HumanoidRootPart"}
local Debris = game:GetService("Debris")

local module = {}

function module.Function(character,color,duration)
	local OverlayParts = Instance.new("Folder")
	OverlayParts.Name = "OverlayParts"
	OverlayParts.Parent = character
		for i,v in pairs(character:GetChildren()) do
			if v:IsA("Part") or v:IsA("MeshPart") then
				if not table.find(ignorelist,v.Name) then
					local weld = Instance.new("WeldConstraint")
					local clonedpart = Instance.new("Part")
					clonedpart.Name = v.Name
					clonedpart.Material = Enum.Material.SmoothPlastic
					clonedpart.Size = v.Size * 1.25
					clonedpart.Position = v.Position
					clonedpart.BrickColor = color
					clonedpart.CanCollide = false
					clonedpart.Transparency = 0.6
					weld.Part0 = v
					weld.Part1 = clonedpart
					clonedpart.Parent = OverlayParts
					weld.Parent = OverlayParts
	Debris:AddItem(OverlayParts,duration) --overlay duration

return module


is there anyway to disable this overlapping effect?

also i tried to use unionasync to union the parts but it gave me a error “Unable to cast value to Objects”

The best way to achieve this is just to create a complete clone of the parts you want to make an “outline” of. For example if you want a R15 Rig, then create a copy of each of it’s parts, size them up ever so slightly to avoid Z-Fighting, change their transparency/color and then weld each part to the existing part of the same name.

Also I HIGHLY recommend to avoid using the Live CSG (Unioning) in run-time as it’s extremely performance heavy. I haven’t personally tested the V2 of Roblox’s CSG which they released semi recently but from what I’ve heard it’s not much better in terms of run-time performance