Help With Raycasting Onto Whitelisted Part Within Range

[Hello everybody, my code currently outlines my ray, and it’s getting what’s within the range of 7 studs, here’s the code for a visual explanation :

while wait(.1) do
local function castRay()
local origin = pA.Position
local distance = (pA.CFrame.LookVector - pA.Position).Magnitude
local direction = pA.CFrame.LookVector

	local params = RaycastParams.new()
	
	local ray = workspace:Raycast(origin, direction * 7, params) --[[sends a ray out 
	7 studs in the direction it's pointing]]
	
	--The conditional statement below creates the visible ray
	if ray then
		print(ray)
		rayPart.Color = Color3.fromRGB(255, 255, 0)
		rayPart.Material = Enum.Material.Neon
		rayPart.Parent = workspace
		rayPart.Anchored = true
		distance = (ray.Position - origin).Magnitude
		rayPart.CFrame = CFrame.new(origin, ray.Position) * CFrame.new(0, 0, -distance / 2)
		rayPart.Size = Vector3.new(.5, .5, distance)
		rayPart.CanCollide = false
		rayPart.CanQuery = false
	end
end

castRay()

end

My goal here is to get the ray to detect a whitelisted part within the range of the given range of studs, and track it (like you would cast a ray between 2 parts, for example)

I’m posting this because I can only find few beginner-friendly sources on raycasting that deal with these issues directly since the update. :face_with_diagonal_mouth:

As a plus to getting this solved, I want to analyze the code to gain more axioms for scripting raycasts in the future, any and all help is appreciated.