How to ignore specific part name when raycasting

This is a fairly simple sounding question that I seem unable to answer, I know that FindRayWithIgnoreList exists but I cant figure how to check if the name is HumanoidRootPart and ignore it (I’m making a mirror and the humanoid root part shows up as grey instead of the torso color).
the code that I’m using:

local ray = Ray.new(script.Parent.Position,script.Parent.CFrame.LookVector*100)
while true do
local part = game.Workspace:FindPartOnRayWithIgnoreList(ray, --[[HumanoidRootPart]])
	wait(.1)
		if part then
		script.Parent.BrickColor = part.BrickColor
		else script.Parent.BrickColor = BrickColor.new("Institutional white")
	end
end

There is no specific function for what you want. Like you said, FindRayWithIgnoreList should be used. The IgnoreList would contain every HumanoidRootPart.

If you care only about player characters, you can use the Player.CharacterAdded event to detect when a new player’s character spawns. You get the character’s HumanoidRootPart to insert it into some table. If a player dies/leaves, remove their HumanoidRootPart from the table. So when you use FindRayWithIgnoreList, the IgnoreList would be that table.

Otherwise, you can search every descendant in workspace using workspace:GetDescendents(), and if a part is a HumanoidRootPart, then insert into a table. Every time a new instance is added to workspace, check it’s contents for a HumanoidRootPart. If it does, insert into the table. When an instance is removed, remove it from the table. That table would be your IgnoreList.

These can be improved with some optimizations.

But wait, what if you don’t want to do all that? You can have your own custom function that does this! First, you create a new table for the raycasting. Then, you can get all descendants of workspace (or only player characters) and check for a HumanoidRootPart. If there is one, add it to a table. Use the table for FindRayWithIgnoreList

2 Likes