Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How does FindPartOnRay work?

So on the wiki it says it triggers when a part intercepts your ray, but can someone, using code, explain how I would execute this as;

local part, endPoint = Workspace:FindPartOnRay(ray)

doesn't make sense to me.

And how will I use it for a function that fires on this event firing (it being intercepted).

1 answer

✓ Accepted answer

Workspace:FindPartOnRay(ray) does as it's told (Finds a BasePart that is colliding with the ray closest to the ray's origin, like a laser hitting a wall).

In your case, part is the BasePart that the ray has collided with, and endpoint is the location of the collision, a Vetcor3.

You can use it for a function like this:

function YourFunction()
--stuff
end

ray = Ray.new() --Your ray
local part, endpoint = Workspace:FindPartOnRay(ray)
if part then YourFunction() end

Workspace:FindPartOnRay(ray) isn't an event, so you'd have to run the function when you want to check for intersecting parts.

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.