Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I prevent "workspace:FindPartOnRay()" from getting Nil?

Asked by 4 years ago
Edited 4 years ago

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
0
If it didn't find a part on a ray, it returns nil. Why would you want to not return nil? programmerHere 371 — 4y
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? IllIIll1 17 — 4y

Answer this question