why not just do something like this?
local size = Vector3.new(4,4,4) --The size value can alternatively be used to make the function operate on a grid.
--[[
axisPlace takes five arguments -
obj: The part which the new part is spawned from and positioned around.
axis: The axis you want to move in.
polarity: Is your movement positive (true) or negative (false)?
useDisplace: Are you using a displacement (true) or not using it (false)?
displace: Number value which displaces the object a certain distance on the chosen axis.
]]
local function axisPlace(obj,axis,polarity,useDisplace,displace)
local object = Instance.new("Part")
object.Anchored = true
object.CanCollide = false
object.Size = size
object.Parent = obj
if axis == 'x' then
if polarity then
object.Position = obj.Position + Vector3.new(object.Size.X,0,0)
if useDisplace then
object.Position = object.Position + Vector3.new(displace,0,0)
end
else
object.Position = obj.Position - Vector3.new(object.Size.X,0,0)
if useDisplace then
object.Position = object.Position - Vector3.new(displace,0,0)
end
end
elseif axis == 'y' then
if polarity then
object.Position = obj.Position + Vector3.new(0,object.Size.Y,0)
if useDisplace then
object.Position = object.Position + Vector3.new(0,displace,0)
end
else
object.Position = obj.Position - Vector3.new(0,object.Size.Y,0)
if useDisplace then
object.Position = object.Position - Vector3.new(0,displace,0)
end
end
elseif axis == 'z' then
if polarity then
object.Position = obj.Position + Vector3.new(0,0,object.Size.Z)
if useDisplace then
object.Position = object.Position + Vector3.new(0,0,displace)
end
else
object.Position = obj.Position - Vector3.new(0,0,displace)
if useDisplace then
object.Position = object.Position - Vector3.new(0,0,displace)
end
end
end
end
axisPlace(script.Parent,'x',true,false,nil)
axisPlace(script.Parent.Part,'y',true,false,nil)
If you’re using explicitly 4x4x4 blocks, this should be good enough. If your parts vary in size, you may have to use a conceptual grid.