How can i fix this script for making points on part surface?

Hello everyone! So, i want to detect if part is visible on player’s screen.

local function getPoints(part,size)
	local points = {}

	local sizeX = part.Size.X * size
	local sizeY = part.Size.Y * size
	local sizeZ = part.Size.Z * size
	for x=1, sizeX + 1 do
		for y=1, sizeY + 1 do
			for z=1, sizeZ + 1 do
				local point = Vector3.new(part.Position.X-(sizeX/2-(x-1))/size, part.Position.Y-(sizeY/2-(y-1))/size, part.Position.Z-(sizeZ/2-(z-1))/size)
				if point.X == part.Position.X + sizeX / size / 2 or point.X == part.Position.X - sizeX / 2 / size or point.Y == part.Position.Y + sizeY / size / 2 or point.Y == part.Position.Y - sizeY / size / 2 or point.Z == part.Position.Z + sizeZ / size / 2 or point.Z == part.Position.Z - sizeZ / size / 2 then
					local att = Instance.new("Attachment")
					att.Parent=workspace.CoolPart
					att.WorldPosition = point
					att.Visible = true
					table.insert(points, point)
				end
			end
		end
	end
	return points
end
local points = getPoints(workspace.CoolPart,0.5)
print(#points)

I’m not so good at math and not perfect in scripting, but i managed to make this script which works fine with parts which size is like 2, 4, 6, 8, 10, 12, 14 and so on

Size is 18, 10, 10
image

But if the number is odd (1,3,5,7,9) or if it’s less than 1 it will look like that

Size is 19, 11, 10
image
(some surfaces doesn’t have points beacuse there’s if function, which checks if the point is being at surface or edge of the part, but they are not so they deletes

I want to make it like that, so game puts points at set distance, and if point can’t fit into part (going out of it) and last point is not at the edge (as you can see in the last screenshot) game squishes the points, so everything can fit, and then leaves it like that. How could i do that? (sorry if my english or coding is bad)