How do I make raycast ignore anything with a humanoid in it

I would like to have a raycast that ignores players and npc’s (anything with a humanoid in it)

1 Like

You’d just make a table and add all models with humanoids into it, as a reference for a raycast’s blacklist

Example:

local ignoreTable = {}

for i, v in pairs(game:GetService("Players"):GetPlayers()) do
    table.insert(ignoreTable, v.Character)
end

for i,v in pairs(workspace.npcFolder:GetChildren()) do
	if v:FindFirstChild("Humanoid") then
		table.insert(ignoreTable, v)
	end
end

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = ignoreTable

local result = workspace:Raycast(origin, direction, raycastParams)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.