Hexagon grid problem


local tile = script.Hexagon

local boardSize = 9
local pos = Vector3.new(0,0,0)
task.wait(1)
for x=1,boardSize do
	local start,finish = nil,nil
	if x<math.ceil(boardSize/2) then
		start,finish = math.ceil(boardSize/2)-x+1,boardSize
	else
		start,finish = 1,boardSize-math.floor(x-boardSize/2)
	end
	for y=start,finish do
		print(x,y)
		local newTile = tile:Clone()
		newTile.Parent = workspace
		local offset = 0
		print(y%2)
		if y%2==0 then
			offset = newTile.Size.X*0.5
		end
		newTile.Position = pos + Vector3.new((x+math.floor(y/2))*newTile.Size.X-offset,0,y*newTile.Size.Z*0.75)
		newTile.BrickColor = BrickColor.Random()
		task.wait(0.1)
	end
end

This works, however i can’t find a way to get the horizontal X value, so what i want is
image
How can i get this number? This is not my code i found it somewhere btw.

Wouldn’t the horizontal count be equal to finish on each for x loop?

Nope, i would also think so but it seems to be completely different, you can try the code yourself by grabbing yourself a part and using that as the hexagon, script in workspace

((math.abs(boardSize - (boardSize-math.floor(x-boardSize/2)))*-1) + boardSize)