This script splits large bricks into smaller bricks, then repeats on the smaller bricks until they get too small.
Does anyone see a way I can improve this? Make it more efficient/less laggy?
When I use this for my bomb, it lags so much.
function Split(part)
local Origin = part
local X = Origin.Position.x
local Y = Origin.Position.y
local Z = Origin.Position.z
local SizeX = Origin.Size.x/(Origin.Size.x/(Origin.Size.x/4) )
local SizeY = Origin.Size.y/(Origin.Size.y/(Origin.Size.y/4) )
local SizeZ = Origin.Size.z/(Origin.Size.z/(Origin.Size.z/4) )
if(SizeX*SizeY*SizeZ>=1)then
local A = Instance.new("SpawnLocation")
local B = Instance.new("SpawnLocation")
local C = Instance.new("SpawnLocation")
local D = Instance.new("SpawnLocation")
local E = Instance.new("SpawnLocation")
local F = Instance.new("SpawnLocation")
local G = Instance.new("SpawnLocation")
local H = Instance.new("SpawnLocation")
function Copy(Fragment)
Fragment.BrickColor = Origin.BrickColor
Fragment.Material = Origin.Material
Fragment.TopSurface = Origin.TopSurface
Fragment.BottomSurface = Origin.BottomSurface
Fragment.Anchored = Origin.Anchored
Fragment.Locked = Origin.Locked
Fragment.formFactor = Origin.formFactor
if( ((Origin.Size/2).x%2) == 0 )and( ((Origin.Size/2).y%2) == 0 )and( ((Origin.Size/2).z%2) == 0 )then
Fragment.Size = Origin.Size/2
Mesh = Instance.new("BlockMesh")
Mesh.Parent = Fragment
else
Fragment.Size = Origin.Size/2
Mesh = Instance.new("BlockMesh")
local x = 0
local y = 0
local z = 0
if ( ( ((Origin.Size/2)*10).x%2) == 1 )or( ((Origin.Size/2).x%2) == 1 ) then
x = 0.5
end
if ( ( ((Origin.Size/2)*10).y%2) == 1 )or( ((Origin.Size/2).y%2) == 1 ) then
y = 0.5
end
if ( ( ((Origin.Size/2)*10).z%2) == 1 )or( ((Origin.Size/2).z%2) == 1 ) then
z = 0.5
end
Mesh.Scale = ( (((Origin.Size/2)-Vector3.new(x, y, z))*10)/((((Origin.Size/2)-Vector3.new(x, y, z))*10)-(Vector3.new(x*2, y*2, z*2)*10)) )*1
Mesh.Parent = Fragment
end
Fragment.Parent = Origin.Parent
end
Copy(A)
Copy(B)
Copy(C)
Copy(D)
Copy(E)
Copy(F)
Copy(G)
Copy(H)
A.CFrame = CFrame.new(Vector3.new(X + SizeX, Y + SizeY, Z + SizeZ ))
B.CFrame = CFrame.new(Vector3.new(X + SizeX, Y + SizeY, Z - SizeZ ))
C.CFrame = CFrame.new(Vector3.new(X + SizeX, Y - SizeY, Z + SizeZ ))
D.CFrame = CFrame.new(Vector3.new(X + SizeX, Y - SizeY, Z - SizeZ ))
E.CFrame = CFrame.new(Vector3.new(X - SizeX, Y + SizeY, Z + SizeZ ))
F.CFrame = CFrame.new(Vector3.new(X -SizeX, Y + SizeY, Z - SizeZ ))
G.CFrame = CFrame.new(Vector3.new(X - SizeX, Y - SizeY, Z + SizeZ ))
H.CFrame = CFrame.new(Vector3.new(X - SizeX, Y - SizeY, Z - SizeZ ))
Split(A)
Split(B)
Split(C)
Split(D)
Split(E)
Split(F)
Split(G)
Split(H)
part:remove()
end
end
Split(script.Parent) |