FindPartOnRayWithIgnoreList()

How would I use this function to ignore multiple arrays?

This works fine
FindPartOnRayWithIgnoreList(ray, Character:GetDescendants())

But this doesn’t
FindPartOnRayWithIgnoreList(ray, {Character:GetDescendants(),workspace.Items:GetDescendants()})

3 Likes

saying {table1,table2} creates a new table with 2 tables in it. You will need to copy 1 table into the other and use that table.

t1 = char:GetDescendants()
for _,v in pairs(t2) do
table.insert(t1,v)
end

Preferably copy the shortest table into the longest one.

I usually just create a table with items to ignore.

 local ignore = {Character, workspace.Items}
FindPartOnRayWithIgnoreList(ray,ignore)
6 Likes

You don’t need to use GetDescendants for this, the ignore list makes it ignore all descendants anyway.
Just this will work:

FindPartOnRayWithIgnoreList(ray, {Character, workspace.Items})
5 Likes

Oh wow, I only made this thread because I swear I tried it that way and it didn’t work. Thanks!

whenever i don’t do :GetDescendants() - it’s “Unable to cast value”

What are you passing? This is an error with your own implementation. Passing an instance automatically ignores it’s descendants as well.

I was just passing the character Variable

local char = workspace:WaitForChild(player.Name)
player.CharacterAdded:Connect(function(character)
    char = character
end)

This worked:

function getMouseAndTargetLocation(cursorPosition)
   local origin = char.Head.Position
   local direction = (Mouse.Hit.p - origin).Unit * 6
   local ray = Ray.new(origin, direction)
   return workspace:FindPartOnRayWithIgnoreList(ray, char:GetDescendants())
end

This didn’t:

function getMouseAndTargetLocation(cursorPosition)
       local origin = char.Head.Position
       local direction = (Mouse.Hit.p - origin).Unit * 6
       local ray = Ray.new(origin, direction)
       return workspace:FindPartOnRayWithIgnoreList(ray, char)
end

Output: “Unable to cast value to Object”

The second one doesn’t work because the second argument needs to be a table. Wrap the character variable to fix the issue.

return workspace:FindPartOnRayWithIgnoreList(ray, {char})

The one with GetDescendants works because the function returns a table, while passing just the character passes a lone instance. You thus need to pass a table yourself that includes the character.

2 Likes

This kind of counts as a bug maybe, roblox should add this as a feature honestly it sounds annoying