How do I check if an NPC doesn't have a name from a table?

I’m currently working on an AI for my Guest defense like gamemode, so I have the issue that the other AIs are accidentally shooting themselves, what I have tried is to use a pairs code to get the other AI names from a table, something like this:

for _, Name in pairs(Names) do
    if ObjectThatGotHitByBullet.Parent.Name ~= Name then
        --Damage code here
    end
end

However, the problem is that if only one Name is not the name of the NPC, it will damage the other NPC, I don’t know how to fix this, thanks for reading.

Is the Name variable already defined?

Can’t you simply check if the object that was hit’s name is different the person who shooted?

Name is each name set inside the table Names, Name is a string.

There will be different names of NPCs, such as Soldier, Quickster, etc.

Oh yeah I see now. Didn’t see it being defined in the for loop the first read through.

1 Like

What if you simply have the name of the humanoid something like “AI,” then when the when they are shot, if the humanoid has that exact name, don’t deal damage!

So you would have all the names in a table and use table.find:

local Names = {} -- the names

if not table.find(Names, ObjectThatGotHitByBullet.Parent.Name) then
    -- do something
end