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

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

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

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).

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