Generating a grid of parts from the middle of a specific position

I’m trying to generate a grid of parts from a position.

Screen Shot 2021-06-14 at 3.05.11 PM

Screen Shot 2021-06-14 at 3.05.27 PM

local StudWidth = 5
local StudsX = 10
local StudsZ = 10
local StudsY = 4

local Position = script.Parent.Position

for x = 1, StudsX * StudWidth, StudWidth do
	for y = 1, StudsY * StudWidth, StudWidth do
		for z = 1, StudsZ * StudWidth, StudWidth do

			local part = Instance.new("Part",workspace)
			part.Anchored = true
			part.CanCollide = false
			part.Shape = "Ball"
			part.Material = Enum.Material.Neon
			part.Size = Vector3.new(0.5,0.5,0.5)
			part.Position = Position + Vector3.new(x,y,z)

		end
	end
end

The green part is the position from where I want to generate the grid from. I know why it’s not working, however I have no idea how to generate the grid with it being in the middle of the green part.

I’ve searched for topics covering this issue and have found none.

2 Likes

You minus by the vector 3 max length stufsX*stud width divided by two. Remember to do this with all three XYZ components.

I did that wrong wait a second!!!

Yep that should be it just needs the divide by two to center it.

same, I think the easiest way to do this is to tell the game that your part position is somewhere else so it seems like the green part is in the middle

let me try to figure that out rq
local Position = script.Parent.Position - Vector3.new((StudX * StudWidth) / 2, (StudY * StudWidth) / 2, (StudZ * StudWidth) / 2)
I’m at school rn so tell me if I did anything wrong

I realized that already, don’t have to tell me :sweat_smile: