Script created raycast returns invalid get index from the position field

Godot Version

godot 4

Question

this script created raycast(and all others I’ve tried) return the following error when trying to access the position field of the created dictionary.

“Invalid get index ‘(121.5854, -12.69985, 15.1143)’ (on base: ‘Dictionary’).”

what am I doing wrong?

here’s my script

			var space_state = get_world_3d().direct_space_state
			var query = PhysicsRayQueryParameters3D.create(pathPoints[pi].position, targetNearest.position)
			
			var result = space_state.intersect_ray(query)
			
			# this is the error
			if child.position.distance_to(result[position]) < curDistance:

SOLUTION:

#checks for the path point nearest the current point in the direction of the target point
			var space_state = get_world_3d().direct_space_state
			var query = PhysicsRayQueryParameters3D.create(pathPoints[pi].position, target.position)
			
			var result = space_state.intersect_ray(query)
			var rayPos : Vector3
			if result:
				print("rayWorked")
				rayPos = result.position
			# this is the error
			if child.position.distance_to(rayPos) < curDistance: