How do I get the Position from a Raycast hitting Terrain?

Heyo. I want to get the position of terrain I hit with a raycast. My issue is that the position is 0,0,0 when the code has clearly hit a bit of terrain.

I have looked at all of these so far and have tried solving this for a good hour now:

For more clarification, I am making a boss fight attack. I need to get the position of the terrain from a raycast so I can make a part go to the position where the raycast hits.

Here is the code. Also, it is a server script:
                local rayOrigin = script.Parent.HumanoidRootPart.Position
		local rayDirection = Vector3.new(0,-100,0)
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {script.Parent}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		
		local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
		
		if raycastResult then
			local hitPart = raycastResult.Instance
			local positionOfSurfaceHit = hitPart.Position
			local materialFromRay = raycastResult.Material
			print(positionOfSurfaceHit)
			print(hitPart)
			print(materialFromRay)
			
		end

Here is the output of the code:

image

2 Likes

It should be raycastResult.Position, Terrain has no position so Terrain.Position always gives 0,0,0.

1 Like