Ok so I’ve been trying to make a voxel destruction system for my game, I got most of it down but now I have to solve one thing:
How could I make the part’s size 1x1x1?
Most of these scripts I got from other forums and modified.
function module:divide(part:BasePart)
local halfX = part.Size.X / 2
local halfY = part.Size.Y / 2
local halfZ = part.Size.Z / 2
local smallSize = Vector3.new(halfX, halfY, halfZ)
local offsets = {
Vector3.new(-0.5, -0.5, -0.5),
Vector3.new(-0.5, -0.5, 0.5),
Vector3.new(-0.5, 0.5, -0.5),
Vector3.new(-0.5, 0.5, 0.5),
Vector3.new( 0.5, -0.5, -0.5),
Vector3.new( 0.5, -0.5, 0.5),
Vector3.new( 0.5, 0.5, -0.5),
Vector3.new( 0.5, 0.5, 0.5),
}
for _, offset in ipairs(offsets) do
local smallPart = part:Clone()
smallPart.Size = smallSize
smallPart.CFrame = part.CFrame * CFrame.new(offset * smallSize)
smallPart.Parent = part.Parent
end
part:Destroy()
end
return module
local function hitbox(size: number, part: BasePart)
local hb = Instance.new("Part")
hb.Size = Vector3.new(size, size, size)
hb.CFrame = part.CFrame
hb.Anchored = true
hb.CanCollide = false
hb.BrickColor = BrickColor.new("Bright red")
hb.Transparency = 0.5
hb.Shape = Enum.PartType.Ball
hb.Parent = workspace
game.Debris:AddItem(hb, .1)
for i = 1, 6 do
local hitparts = workspace:GetPartsInPart(hb)
local divided = false
for _, v in ipairs(hitparts) do
if i == 6 and v:HasTag("map_piece") then
v:Destroy()
elseif v:HasTag("map_piece") then
mod:divide(v)
end
end
end
end
hitbox(10, workspace.Part)
--part is the ball in the picture
What I got:
What I’m trying to achieve:

