Raycast ignores terrain

So this “find highest point on terrain” thing i’ve been working on seems to ignore terrain where it shouldn’t.


local function GetTerrainHighestPoint(Ray)
	local Parts = {}
	local LastPart, Position

		LastPart, Position = workspace:FindPartOnRayWithIgnoreList(Ray, Parts)
		table.insert(Parts, LastPart)
	until LastPart == workspace.Terrain
	return Position

And some pictures for visualisation. First is the origin of the rays, and the second is just a part streched from the ray origin to -1000. (since it only goes down)

So if the ray intersects the terrain, and it could detect it 9 times, what gives on the tenth?
Any guesses? Any help is appreciated.

So something came up:

  23:29:28.163  Caves: 100% taking a break  -  Server - Script:57
  23:29:29.509   ▶ nil (x259)  -  Server - Script:69

It doesn’t suceed 9 times and then fails… the method whitch i used to “see” the rays only placed parts when the tree density was above a level so it places a tree. So it would fail instantly.


local Position = GetTerrainHighestPoint(Ray.new(Vector3.new(x*4,500,z*4), Vector3.new(x*4,-500,z*4)))

This is the ray i give, but if i remove the *4 it works but the map it generates shrinks.

So why is it above terrain, and not detecting it when it’s *4? now 100% failure rate :partying_face:
And why does it work shrunk down when i don’t multiply?
Both cases are above terrain, with different results.

Now with edited title.

This is a correctly visualised ray. The direction shouldn’t have been multiplied. :clown_face: