I used FindPartOnRayWithIgnoreList for my raycasting script. I want to make it so that it will ignore all players and target only the NPCS i created instead. Problem is, i can't find a way to add a table of all players in the game inside the ignore list. Honestly i'm not even sure if that's possible.
local ball = script.Parent
function findTarget()
local radius = 25
local target = nil
for i,v in pairs(game.Workspace:GetChildren()) do
local root = v:FindFirstChild('HumanoidRootPart')
local hum = v:FindFirstChild('Humanoid')
if root and hum then
if (ball.Position - root.Position).magnitude <= radius and hum.Health > 0 then
ball.CFrame = CFrame.new(ball.Position, root.Position)
local ray = Ray.new(ball.Position,(root.Position - ball.Position).Unit * 500)
local hit,position = game.Workspace:FindPartOnRayWithIgnoreList(ray,{})
if hit then
if hit:IsDescendantOf(root.Parent) then
radius = (ball.Position - root.Position).magnitude
target = root
else
print(hit.Name)
end
end
end
end
end
return target
end

5 comments
Have you tried adding a BoolValue to the NPC's Named "IsNPC" and then searching for players with a Humanoid but without a IsNPC tag?
I did the exact opposite, i inserted a tag inside the players to differentiate them from my NPCS, but i soon figured there was no way to get the character model.
Adding onto what boomthefist said, you could add any value inside of the NPC and check if they have the tag, and if not then don't do anything, but if they do have it, then do what you are trying to do.
You could do a for loop of every player and get their character and it to the ignore list.
I'll try it out, thanks! I didn't think of that lol.