function Raycast.FindPartOnRayWithCallbackWithIgnoreList(t,Z,u,B,a,x)local A=t.Direction.Magnitude local b=t.Direction.Unit a=a or 25 local g=0 local Q=t.Origin local R=0 local c,m,I,s repeat local z=Ray.new(Q,b*(A-R))c,m,I,s=WORKSPACE:FindPartOnRayWithIgnoreList(t,Z,u,B,true)local J=x(c,m,I,s)if J==CALLBACKRESULT.Continue then R=(t.Origin-m).Magnitude Q=m elseif J==CALLBACKRESULT.Finished then return c,m,I,s elseif J==CALLBACKRESULT.Fail or J==nil then break end g=g+1 until g>a or R>=A-.1 return end function Raycast.FindPartOnRayWithCallbackWithWhiteList(t,Z,u,B,a)local x=t.Direction.Magnitude local A=t.Direction.Unit local b=t.Origin local g=0 local Q,R,c,m repeat local I=Ray.new(b,A*(x-g))Q,R,c,m=WORKSPACE:FindPartOnRayWithWhiteList(t,Z,u,B,true)local s=a(Q,R,c,m)if s==CALLBACKRESULT.Continue then g=(t.Origin-R).Magnitude b=R elseif s==CALLBACKRESULT.Finished then return Q,R,c,m elseif s==CALLBACKRESULT.Fail or s==nil then break end until g>=x-.1 return end function Raycast.FindPartOnRayWithCallback(t,Z,u,B,a)return Raycast.FindPartOnRayWithCallbackWithIgnoreList(t,{Z},u,B,a)end
--

function Raycast.FindPartOnRayWithCallbackWithIgnoreList(
	ray,
	list,
	terrainCellsAreCubes,
	ignoreWater,
	loopout,
	callbackFunc
)
	local maxDistance = ray.Direction.Magnitude
	local direction = ray.Direction.Unit

	loopout = loopout or 25
	local loopCount = 0

	local lastPosition = ray.Origin
	local distance = 0

	local hit, position, normal, material

	repeat
		local r = Ray.new(lastPosition, direction * (maxDistance - distance))
		hit, position, normal, material =
			WORKSPACE:FindPartOnRayWithIgnoreList(ray, list, terrainCellsAreCubes, ignoreWater, true)
		local result = callbackFunc(hit, position, normal, material)

		if result == CALLBACKRESULT.Continue then
			distance = (ray.Origin - position).Magnitude
			lastPosition = position
		elseif result == CALLBACKRESULT.Finished then
			return hit, position, normal, material
		elseif result == CALLBACKRESULT.Fail or result == nil then
			break
		end

		loopCount = loopCount + 1
	until loopCount > loopout or distance >= maxDistance - 0.1

	return
end

function Raycast.FindPartOnRayWithCallbackWithWhiteList(ray, list, terrainCellsAreCubes, ignoreWater, callbackFunc)
	local maxDistance = ray.Direction.Magnitude
	local direction = ray.Direction.Unit

	local lastPosition = ray.Origin
	local distance = 0

	local hit, position, normal, material

	repeat
		local r = Ray.new(lastPosition, direction * (maxDistance - distance))
		hit, position, normal, material =
			WORKSPACE:FindPartOnRayWithWhiteList(ray, list, terrainCellsAreCubes, ignoreWater, true)
		local result = callbackFunc(hit, position, normal, material)

		if result == CALLBACKRESULT.Continue then
			distance = (ray.Origin - position).Magnitude
			lastPosition = position
		elseif result == CALLBACKRESULT.Finished then
			return hit, position, normal, material
		elseif result == CALLBACKRESULT.Fail or result == nil then
			break
		end
	until distance >= maxDistance - 0.1

	return
end

function Raycast.FindPartOnRayWithCallback(ray, ignore, terrainCellsAreCubes, ignoreWater, callbackFunc)
	return Raycast.FindPartOnRayWithCallbackWithIgnoreList(
		ray,
		{ ignore },
		terrainCellsAreCubes,
		ignoreWater,
		callbackFunc
	)
end
