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

FindPartOnRay not returning values when it should? [ANSWERED]

Asked by 6 years ago
Edited 6 years ago

EDIT: The problem was that the ray cast direction needed to be inverted.


I am rescripting a gun, but came across a problem that breaks the entire gun - FindPartOnRay (and its variants) don't detect parts. I've tried many ways of debugging, but to no avail.

Note that for some reason it does work sometimes, but only works when my character jumps, and when I am aiming at the corner of a part. I assume this is some weird thing with FindPartOnRay.

function Raycast(Start,Finish,Ignore)
    local Direction = (Start-Finish).Unit
    local Direction_Argument = Direction*Settings.Range
    local Cast = Ray_New(Start,Direction_Argument)
    local Hit_Part,Hit_Pos = workspace:FindPartOnRay(Cast,Ignore)

    return Hit_Part,Hit_Pos
end

If I were to print Hit_Part and Hit_Pos it would say:

nil <vector3 end of the ray>


Thank you!

~TDP

0
Try drawing a brick between where the ray was spawned and where it hits to debug. plasma_node 343 — 6y

Answer this question