I'm using "workspace:FindPartOnRay()" with a ray that is the size of the Local Player's screen. It detects Nil unless CurrentCamera is face deep into a Part.. Then it detects the part. How can I blacklist Nil from "workspace:FindPartOnRay()"?

while true do wait(0.4)
	local model = workspace.Model
	local whitelist = model:GetChildren()
	local camera = workspace.CurrentCamera
	local length = 500
	local viewportPoint = camera.ViewportSize
	local unitRay = camera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y, 0)
	local ray = Ray.new(unitRay.Origin, unitRay.Direction * length)
	print(workspace:FindPartOnRayWithWhitelist(ray,whitelist))
end

2 comments

0

If it didn't find a part on a ray, it returns nil. Why would you want to not return nil?

0

i guess i just assumed, if a part was inside the ray then it would return a part instead of nil. because if the ray is the size of the screen then wouldn't every visible part be returned instead of nil?