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


Thank you!

~TDP

1 comment

0

Try drawing a brick between where the ray was spawned and where it hits to debug.