How to return position of nil ray, using Raycast

When I do NewRay.Position, I get nothing in the output. Just cause there’s no part found, I should still get a returned result? How can I do this if FindPartOnRay is deprecated?

return function(start, target)
	local Direction = (target - start).unit
	
	local Params = RaycastParams.new()
	Params.FilterType = Enum.RaycastFilterType.Blacklist
	Params.FilterDescendantsInstances = {BulletsContainer}
	Params.IgnoreWater = true
	
	local NewRay = workspace:Raycast(start, Direction.unit * 999, Params)
	print(NewRay.Position) -- Prints nothing
	return NewRay.Instance, NewRay.Position
end

This works, as hit just returns nil, but endPos is still valid

function(start, target, ignore)
	local dir = (target - start).unit
	local ray = Ray.new(start, dir.unit * 999)
	local hit, endPos = workspace:FindPartOnRay(ray, ignore)
	return hit, endPos
end

If the ray doesn’t hit anything the end position is origin + direction, so in your case the position if the ray didn’t hit would be start + Direction.unit * 999

2 Likes