# Brick Fragmentation - Need Help

Hello,

I’m currently using an ‘older’ brick fragmentation script (I have very minimal scripting knowledge, I am trying to learn.)

This script actually works perfectly, for the most part, on what I’m trying to accomplish. Although, I have one problem… When the brick actually does fragment in a game test it changes the material to a default plastic. I’m trying to get it to where it keeps the material, i.e brick/wood planks/etc.

Would anyone happen to know how I could accomplish this?

• From what I think I’m understanding correctly, this part of the script is the part that determines what happens to the brick when it fragments:
Summary
local xi = size.X >= minimumsize.X*(1+explosion_blastradius/16) and 2 or 1 --to reduce the lagg in large explosions we increase minimumsize based on the explosionradius...
local yi = size.Y >= minimumsize.Y*(1+explosion_blastradius/16) and 2 or 1
local zi = size.Z >= minimumsize.Z*(1+explosion_blastradius/16) and 2 or 1
if xi == 1 and yi == 1 and zi == 1 or (cframe.p-explosion_position).magnitude > size.magnitude/2 + explosion_blastradius then --don�t fragmentate parts, that are too small to fragmentate or too far away from the explosion
if xi == 1 and yi == 1 and zi == 1 then return end --optional
if #storage > 0 then
local p = storage[1]
p.BrickColor = color
p.Size = size
p.BackSurface = backsurface
p.BottomSurface = bottomsurface
p.FrontSurface = frontsurface
p.LeftSurface = leftsurface
p.RightSurface = rightsurface
p.TopSurface = topsurface
p.Transparency = transparency
p.CFrame = cframe
p.Reflectance = reflectance
table.remove(storage,1)
else
local p = Instance.new("Part",fragmentable)
p.BrickColor = color
p.Anchored = true
p.FormFactor = "Custom"
p.Size = size
p.BackSurface = backsurface
p.BottomSurface = bottomsurface
p.FrontSurface = frontsurface
p.LeftSurface = leftsurface
p.RightSurface = rightsurface
p.TopSurface = topsurface
p.Transparency = transparency
p.CFrame = cframe
p.Reflectance = reflectance
end
2 Likes

So, in the parameters for the fragment function, all the information of the brick is being passed (cframe, size, colour, etc).

You need to add ‘material’ as another parameter, then look at where the fragment function is being and look at how the call passes the details of the brick as parameters - then as the material property to the call.

For example:

-- the items within the '(...) are called the parameters.

--from these
function fragment (cframe, size)  -- the function
p.CFrame = cframe
p.Size = size
end

fragment( brick.CFrame,  brick.BrickColor) -- the call

To something like this:

function fragment (cframe, size, material )  -- the function
p.CFrame = cframe
p.Size = size
p.Material = material
end

--include the material of the brick in the call
fragment( brick.CFrame,  brick.BrickColor, brick.Material) -- the call

Okay, so I thought I was editing it properly… I added the material to the function/call. But when I tested this is crashed Studio, lol. I’m obviously doing something wrong, don’t think I understood it right.

Thank you for your help though, I appreciate it!

Script Screenshot

You created a recursive function by accident. Atleast I think it is by accident because the original script doesn’t show that line. Try putting and end before ```fragmentate(cframe,material,size,color…)``

Instaid of having all of the part properties like cframe material etc all as seperate arguments, give the part as an argument. Then just use part[propertyname].

1 Like