function Raycast.FindPartOnRayWithCallbackWithIgnoreList(F,q,Z,s,Q,N)local t=F.Direction.Magnitude local T=F.Direction.Unit Q=Q or 25 local b=0 local h=F.Origin local z=0 local B,W,U,r repeat local l=Ray.new(h,T*(t-z))B,W,U,r=WORKSPACE:FindPartOnRayWithIgnoreList(F,q,Z,s,true)local o=N(B,W,U,r)if o==CALLBACKRESULT.Continue then z=(F.Origin-W).Magnitude h=W elseif o==CALLBACKRESULT.Finished then return B,W,U,r elseif o==CALLBACKRESULT.Fail or o==nil then break end b=b+1 until b>Q or z>=t-.1 return end function Raycast.FindPartOnRayWithCallbackWithWhiteList(F,q,Z,s,Q)local N=F.Direction.Magnitude local t=F.Direction.Unit local T=F.Origin local b=0 local h,z,B,W repeat local U=Ray.new(T,t*(N-b))h,z,B,W=WORKSPACE:FindPartOnRayWithWhiteList(F,q,Z,s,true)local r=Q(h,z,B,W)if r==CALLBACKRESULT.Continue then b=(F.Origin-z).Magnitude T=z elseif r==CALLBACKRESULT.Finished then return h,z,B,W elseif r==CALLBACKRESULT.Fail or r==nil then break end until b>=N-.1 return end function Raycast.FindPartOnRayWithCallback(F,q,Z,s,Q)return Raycast.FindPartOnRayWithCallbackWithIgnoreList(F,{q},Z,s,Q)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
