RaycastAll
Function of: Workspace
Returns: Table
Tags: instance
Given a ray, returns an unordered array of all intersected parts within a max distance. Max limit of 10. Optionally ignores parts that are or are descendants of a specified dynamic
Parameters
| Name | Type | Description |
|---|---|---|
| ray | Ray | The ray to cast with |
| ignoreAndDescendants | Dynamic | The optional dynamic to ignore parts if equal to or children of |
| maxDistance | Number | The max distance in meters the ray will travel |
| onlyCollidable | Boolean |
Example
-- prints the name of all parts when the local player clicks on something
local player = Players.LocalPlayer
local mouse = player.Mouse
mouse.LeftButtonDown:connect(function()
local ray = Ray.new(mouse.origin.p, mouse.origin.lookvector)
local hits = Workspace:RaycastAll(ray, player, 100)
for _, hit in ipairs(hits) do
print('clicked on ' .. hit.name)
end
end)