Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Fragmentation.SplitPart(part, fragmentationSize)
- pcall(part.BreakJoints, part)
- local mass = part:GetMass()
- local size = part.Size
- if (isBlock and ((size.X < fragmentationSize and size.Y < fragmentationSize and size.Z < fragmentationSize)
- or (not part.Anchored and mass < 750))) or (not isBlock and mass < 250000) then
- pcall(Game.Destroy, part)
- elseif isBlock then
- local parts = {part}
- part.FormFactor = Enum.FormFactor.Custom
- local model = Instance.new("Model", part.Parent)
- model.Name = "Fragments"
- local partClone = Instance.new("Part")
- -- NOTE: this custom cloning function solves problems with children in the part (especially parts inside the part).
- -- surface inputs and parameters are ignored since fragmentation messes up the structure anyway.
- -- formfactor is is ignored too because it should always be Custom for fragmentation.
- -- shape is ignored too because block is default and it has already been established that the part is a block.
- -- cframe is ignored too because it is set later on.
- partClone.Anchored = part.Anchored
- partClone.Archivable = part.Archivable
- partClone.BackSurface = part.BackSurface
- partClone.BottomSurface = part.BottomSurface
- partClone.BrickColor = part.BrickColor
- partClone.CanCollide = part.CanCollide
- partClone.Elasticity = part.Elasticity
- partClone.FormFactor = Enum.FormFactor.Custom
- partClone.Friction = part.Friction
- partClone.FrontSurface = part.FrontSurface
- partClone.LeftSurface = part.LeftSurface
- partClone.Locked = part.Locked
- partClone.Material = part.Material
- partClone.Reflectance = part.Reflectance
- partClone.RightSurface = part.RightSurface
- partClone.RotVelocity = part.RotVelocity
- partClone.Size = part.Size
- partClone.TopSurface = part.TopSurface
- partClone.Transparency = part.Transparency
- partClone.Velocity = part.Velocity
- for _, data in ipairs(Fragmentation.AXIS_DATA) do
- local axisName, axisNormal = data[1], data[2]
- local axisSize = size[axisName]
- if axisSize >= fragmentationSize then
- size = (Vector3.new(1, 1, 1) - 0.5 * data[2]) * size
- partClone.size = size
- for partIndex = 1, #parts do
- local part = parts[partIndex]
- local cframe = part.CFrame
- part.Size = size
- local clone = partClone:Clone()
- part.CFrame = cframe * CFrame.new((-0.25 * axisSize) * axisNormal)
- clone.CFrame = cframe * CFrame.new((0.25 * axisSize) * axisNormal)
- clone.Parent = model
- parts[#parts + 1] = clone
- end
- end
- end
- for _, part in ipairs(parts) do
- part:MakeJoints()
- end
- else
- return false
- end
- return true
- end
- local lp = game.Players.LocalPlayer
- local mouse = lp:GetMouse()
- mouse.Button1Down:connect(function()
- function Fragmentation.SplitPart(mouse.Target, 5)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement