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

(Raycast) How to ignore descendants of models with a certain name?

Asked by 10 years ago

So I took this raycast script from the wiki. How can I do it so that it ignores the descendants of a model named "Potato"?

local ray = Ray.new(
Weapon.Handle.CFrame.p, -- origin
(mouse.Hit.p - Weapon.Handle.CFrame.p).unit * 500 -- direction
) 
local character1 = game.Players.LocalPlayer.Character
local model = ?
ignore = {character1, model}

local hit, position = Workspace:FindPartOnRayWithIgnoreList(ray, ignore)

Thanks!

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

I am unsure of whether or not you can simply pass Models to the ignore list.

If so, just using model = workspace.Potato may work.

Otherwise:


Using simple recursion we can get make a getParts function by noting the following:

The descendant parts of an object are the BasePart-children of that object, as well as the BasePart-descendants of its other children.

function getParts(mod)
    local parts = {}
    for _, child in pairs(mod:GetChildren()) do
        if child:IsA("BasePart") then
            table.insert(parts,child)
        end
        for _, part in pairs(getParts(child)) do
            table.insert(parts,part)
        end
    end
    return parts
end

We could then pass getParts(workspace.Potato).

Ad

Answer this question