local E={}DebugEnabled=false Debris=game:GetService("\068\101\098\114\105\115")function E.FracturePart(E)local S=E:FindFirstChild("\066\114\101\097\107\105\110\103\080\111\105\110\116")local c=E:FindFirstChild("\067\111\110\102\105\103\117\114\097\116\105\111\110")local o=false local C=0 local f=false local X=false if DebugEnabled then local E=Instance.new("\080\097\114\116")E.Shape="\066\097\108\108"E.CanCollide=false E.Anchored=true E.Size=Vector3.new(.5,.5,.5)E.Color=Color3.fromRGB(255,0,0)E.Position=S.WorldPosition E.Parent=workspace end local O=E:FindFirstChild("\066\114\101\097\107\083\111\117\110\100")if O then local S=Instance.new("\080\097\114\116")S.Size=Vector3.new(.2,.2,.2)S.Position=E.Position S.Name="\084\101\109\112\111\114\097\114\121\083\111\117\110\100\069\109\105\116\116\101\114"S.Anchored=true S.CanCollide=false S.Transparency=1 local c=O:Clone()c.Parent=S S.Parent=workspace c:Play()Debris:AddItem(S,c.TimeLength)end if c then o=c.DebrisDespawn.Value C=c.DebrisDespawnDelay.Value f=c.WeldDebris.Value X=c.AnchorDebris.Value else warn("\084\104\101 \'\067\111\110\102\105\103\117\114\097\116\105\111\110\' \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 "..(E.Name.."\046 \080\108\101\097\115\101 \105\110\115\101\114\116 \097 \'\067\111\110\102\105\103\117\114\097\116\105\111\110\' \119\105\116\104 \116\104\101 \102\111\108\108\111\119\105\110\103 \118\097\108\117\101\115\059 \'\068\101\098\114\105\115\068\101\115\112\097\119\110\' \040\098\111\111\108\041\044 \'\087\101\108\100\068\101\098\114\105\115\' \040\098\111\111\108\041\044 \'\068\101\098\114\105\115\068\101\115\112\097\119\110\068\101\108\097\121\' \040\110\117\109\098\101\114\047\105\110\116\041"))end if not S then warn("\084\104\101 \'\066\114\101\097\107\105\110\103\080\111\105\110\116\' \097\116\116\097\099\104\109\101\110\116 \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 "..(E.Name.."\046 \080\108\101\097\115\101 \105\110\115\101\114\116 \097\110 \097\116\116\097\099\104\109\101\110\116 \110\097\109\101\100 \'\066\114\101\097\107\105\110\103\080\111\105\110\116\'"))end local j=S.Position.Y local r=S.Position.Z local H=Instance.new("\087\101\100\103\101\080\097\114\116")local n=Instance.new("\087\101\100\103\101\080\097\114\116")local v=Instance.new("\087\101\100\103\101\080\097\114\116")local s=Instance.new("\087\101\100\103\101\080\097\114\116")local w=E:FindFirstChild("\066\114\101\097\107\083\111\117\110\100")H.Material=E.Material H.Color=E.Color H.Transparency=E.Transparency H.Size=E.Size-Vector3.new(0,E.Size.Y/2-j,E.Size.Z/2+r)local l=H.Size.Y local M=H.Size.Z H.CFrame=E.CFrame*CFrame.new(0,j-H.Size.Y/2,r+H.Size.Z/2)H.CFrame=H.CFrame*CFrame.Angles(math.rad(90),0,0)H.Size=Vector3.new(H.Size.X,M,l)local W=H:Clone()W.CFrame=W.CFrame*CFrame.Angles(math.rad(180),0,0)n.Material=E.Material n.Color=E.Color n.Transparency=E.Transparency n.Size=E.Size-Vector3.new(0,E.Size.Y/2+j,E.Size.Z/2+r)n.CFrame=E.CFrame*CFrame.new(0,j+n.Size.Y/2,r+n.Size.Z/2)local F=n:Clone()F.CFrame=F.CFrame*CFrame.Angles(math.rad(180),0,0)v.Material=E.Material v.Color=E.Color v.Transparency=E.Transparency v.Size=E.Size-Vector3.new(0,E.Size.Y/2+j,E.Size.Z/2-r)local K=v.Size.Y local T=v.Size.Z v.CFrame=E.CFrame*CFrame.new(0,j+v.Size.Y/2,r-v.Size.Z/2)v.CFrame=v.CFrame*CFrame.Angles(math.rad(90),0,0)v.Size=Vector3.new(v.Size.X,T,K)local m=v:Clone()m.CFrame=m.CFrame*CFrame.Angles(math.rad(180),0,0)s.Material=E.Material s.Color=E.Color s.Transparency=E.Transparency s.Size=E.Size-Vector3.new(0,E.Size.Y/2-j,E.Size.Z/2-r)s.CFrame=E.CFrame*CFrame.new(0,j-s.Size.Y/2,r-s.Size.Z/2)local D=s:Clone()D.CFrame=D.CFrame*CFrame.Angles(math.rad(180),0,0)local b={H;W,n;F,v;m,s,D}local B={}local A=nil for S,c in ipairs(b)do table.insert(B,c)if not A then A=c end c.Anchored=X if not X then c.Velocity=E.Velocity c.RotVelocity=E.RotVelocity end if f and A then local E=Instance.new("\087\101\108\100\067\111\110\115\116\114\097\105\110\116")E.Name="\083\104\097\114\100\087\101\108\100"E.Part0=A E.Part1=c E.Parent=c end c.Name="\083\104\097\114\100"c.Parent=E.Parent if o then Debris:AddItem(c,C)end end E:Destroy()return B end return E


local Module = {}

DebugEnabled = false

Debris = game:GetService("Debris")

function Module.FracturePart(PartToFracture)
	
	local BreakingPointAttachment = PartToFracture:FindFirstChild("BreakingPoint")
	
	-- Settings
	local Configuration = PartToFracture:FindFirstChild("Configuration")
	
	local DebrisDespawn = false
	local DebrisDespawnDelay = 0
	local WeldDebris = false
	local AnchorDebris = false
	
	if DebugEnabled then
		local DebugPart = Instance.new("Part")
		DebugPart.Shape = "Ball"
		DebugPart.CanCollide = false
		DebugPart.Anchored = true
		DebugPart.Size = Vector3.new(0.5, 0.5, 0.5)
		DebugPart.Color = Color3.fromRGB(255, 0, 0)
		DebugPart.Position = BreakingPointAttachment.WorldPosition
		DebugPart.Parent = workspace
	end
	
	local BreakSound = PartToFracture:FindFirstChild("BreakSound")
	
	if BreakSound then
		local SoundPart = Instance.new("Part")
		SoundPart.Size = Vector3.new(0.2, 0.2, 0.2)
		SoundPart.Position = PartToFracture.Position
		SoundPart.Name = "TemporarySoundEmitter"
		SoundPart.Anchored = true
		SoundPart.CanCollide = false
		SoundPart.Transparency = 1
		local Sound = BreakSound:Clone()
		Sound.Parent = SoundPart
		SoundPart.Parent = workspace
		Sound:Play()
		Debris:AddItem(SoundPart, Sound.TimeLength)
	end
	
	if Configuration then
		DebrisDespawn = Configuration.DebrisDespawn.Value
		DebrisDespawnDelay = Configuration.DebrisDespawnDelay.Value
		WeldDebris = Configuration.WeldDebris.Value
		AnchorDebris = Configuration.AnchorDebris.Value
	else
		warn("The 'Configuration' is not a valid member of " .. PartToFracture.Name .. ". Please insert a 'Configuration' with the following values; 'DebrisDespawn' (bool), 'WeldDebris' (bool), 'DebrisDespawnDelay' (number/int)")
	end
	
	if not BreakingPointAttachment then
		warn("The 'BreakingPoint' attachment is not a valid member of " .. PartToFracture.Name .. ". Please insert an attachment named 'BreakingPoint'")
	end
	
	local BreakingPointY = BreakingPointAttachment.Position.Y
	local BreakingPointZ = BreakingPointAttachment.Position.Z
	
	local ShardBottomLeft = Instance.new("WedgePart")
	local ShardBottomRight = Instance.new("WedgePart")
	local ShardTopLeft = Instance.new("WedgePart")
	local ShardTopRight = Instance.new("WedgePart")
	
	local BreakSound = PartToFracture:FindFirstChild("BreakSound")
	
	-- Bottom Left
	ShardBottomLeft.Material = PartToFracture.Material
	ShardBottomLeft.Color = PartToFracture.Color
	ShardBottomLeft.Transparency = PartToFracture.Transparency
	ShardBottomLeft.Size = PartToFracture.Size - Vector3.new(0, (PartToFracture.Size.Y / 2) - BreakingPointY, (PartToFracture.Size.Z / 2) + BreakingPointZ)
	local OldSizeY = ShardBottomLeft.Size.Y
	local OldSizeZ = ShardBottomLeft.Size.Z
	ShardBottomLeft.CFrame = PartToFracture.CFrame * CFrame.new(0, BreakingPointY - (ShardBottomLeft.Size.Y / 2), BreakingPointZ + (ShardBottomLeft.Size.Z / 2))
	ShardBottomLeft.CFrame = ShardBottomLeft.CFrame * CFrame.Angles(math.rad(90), 0, 0)
	ShardBottomLeft.Size = Vector3.new(ShardBottomLeft.Size.X, OldSizeZ, OldSizeY)
	local ShardBottomLeft2 = ShardBottomLeft:Clone()
	ShardBottomLeft2.CFrame = ShardBottomLeft2.CFrame * CFrame.Angles(math.rad(180), 0, 0)
	
	-- Bottom Right
	ShardBottomRight.Material = PartToFracture.Material
	ShardBottomRight.Color = PartToFracture.Color
	ShardBottomRight.Transparency = PartToFracture.Transparency
	ShardBottomRight.Size = PartToFracture.Size - Vector3.new(0, (PartToFracture.Size.Y / 2) + BreakingPointY, (PartToFracture.Size.Z / 2) + BreakingPointZ)
	ShardBottomRight.CFrame = PartToFracture.CFrame * CFrame.new(0, BreakingPointY + (ShardBottomRight.Size.Y / 2), BreakingPointZ + (ShardBottomRight.Size.Z / 2))
	local ShardBottomRight2 = ShardBottomRight:Clone()
	ShardBottomRight2.CFrame = ShardBottomRight2.CFrame * CFrame.Angles(math.rad(180), 0, 0)
	
	-- Top Left
	ShardTopLeft.Material = PartToFracture.Material
	ShardTopLeft.Color = PartToFracture.Color
	ShardTopLeft.Transparency = PartToFracture.Transparency
	ShardTopLeft.Size = PartToFracture.Size - Vector3.new(0, (PartToFracture.Size.Y / 2) + BreakingPointY, (PartToFracture.Size.Z / 2) - BreakingPointZ)
	local OldSizeY = ShardTopLeft.Size.Y
	local OldSizeZ = ShardTopLeft.Size.Z
	ShardTopLeft.CFrame = PartToFracture.CFrame * CFrame.new(0, BreakingPointY + (ShardTopLeft.Size.Y / 2), BreakingPointZ - (ShardTopLeft.Size.Z / 2))
	ShardTopLeft.CFrame = ShardTopLeft.CFrame * CFrame.Angles(math.rad(90), 0, 0)
	ShardTopLeft.Size = Vector3.new(ShardTopLeft.Size.X, OldSizeZ, OldSizeY)
	local ShardTopLeft2 = ShardTopLeft:Clone()
	ShardTopLeft2.CFrame = ShardTopLeft2.CFrame * CFrame.Angles(math.rad(180), 0, 0)
	
	-- Top Right
	ShardTopRight.Material = PartToFracture.Material
	ShardTopRight.Color = PartToFracture.Color
	ShardTopRight.Transparency = PartToFracture.Transparency
	ShardTopRight.Size = PartToFracture.Size - Vector3.new(0, (PartToFracture.Size.Y / 2) - BreakingPointY, (PartToFracture.Size.Z / 2) - BreakingPointZ)
	ShardTopRight.CFrame = PartToFracture.CFrame * CFrame.new(0, BreakingPointY - (ShardTopRight.Size.Y / 2), BreakingPointZ - (ShardTopRight.Size.Z / 2))
	local ShardTopRight2 = ShardTopRight:Clone()
	ShardTopRight2.CFrame = ShardTopRight2.CFrame * CFrame.Angles(math.rad(180), 0, 0)
	
	local ShardDictionary = {ShardBottomLeft, ShardBottomLeft2, ShardBottomRight, ShardBottomRight2, ShardTopLeft, ShardTopLeft2, ShardTopRight, ShardTopRight2}
	
	local shards = {}
	local FirstShard = nil
	for Index, Shard in ipairs(ShardDictionary) do
		table.insert(shards,Shard)
		
		if not FirstShard then
			FirstShard = Shard
		end
		Shard.Anchored = AnchorDebris
		if not AnchorDebris then
			Shard.Velocity = PartToFracture.Velocity
			Shard.RotVelocity = PartToFracture.RotVelocity
		end
		if WeldDebris and FirstShard then
			local Weld = Instance.new("WeldConstraint")
			Weld.Name = "ShardWeld"
			Weld.Part0 = FirstShard
			Weld.Part1 = Shard
			Weld.Parent = Shard
		end
		Shard.Name = "Shard"
		Shard.Parent = PartToFracture.Parent
		if DebrisDespawn then
			Debris:AddItem(Shard, DebrisDespawnDelay)
		end
	end
	PartToFracture:Destroy()
	
	return shards
end

return Module
