Okay, so I'm using rays. I want to see that if the ray is intersected and if the part that intersected it is a specific distance away a function to happen. Here is my current script

local MaxDistance = 10
local Part = script.Parent
local R =  Ray.new(Part.Position, Vector3.new(0,-1*MaxDistance,0))


while wait(1) do
	local PartFound, Pos = workspace:FindPartOnRayWithIgnoreList(R, {Part})
	if PartFound then
		if Part.Position.Y - Pos.Y <= 5 then
			print("Part detected") -- Just a place holder until I can get it working
		else
		
		end
	end
end

My issue is that it is printed that a part is detected even thought there is no part that is intersecting the ray at all. Thank you in advance.

2 comments

0

Try if (Part.Position - Pos).Magnitude <= 5 then

0

Thank you, that's just it