A NPC of mine has a function that ignores targets based on these names. If a model has this name, it will not target it however if it has any other name then it will target it. The problem is that I am not sure how to locate body colors of a model? I have tried these lines, but the NPC breaks and stands still as the code is incorrect:
function findTarget() for _, p in pairs(workspace:GetChildren()) do if p:IsA('Model') and p.Name ~= 'NPCZombie' and p.Name ~= 'NPCDarkness' --and p:FindFirstChild('Body Colors').HeadColor ~= 'Really Black' --and p:FindFirstChild('Head').BrickColor ~= 'Really Black' . --EDIT 1- I have rewritten it as so: function findTarget() local BodyColors = Instance.new("BodyColors") for _, p in pairs(workspace:GetChildren()) do if p:IsA('Model') and p.Name ~= 'NPCZombie' and p.Name ~= 'NPCDarkness' --and p.BodyColors.HeadColor.Name == 'Really black' --It still does not work
The rest of the script is not the problem, but how am I supposed to find body colors or brick colors so NPCs with those colors are not targeted?
You are comparing something which is never true All properties of BodyColors (exclude Color3) return a BrickColor. A String is not a BrickColor.
local BodyColors = Instance.new("BodyColors") print( type(BodyColors.HeadColor) ) --> BrickColor
Therefor,
BodyColors.HeadColor == "Really black" --never true! if you compare a datatype which doesn't match, it will always be false!
As we can see here
local a = BrickColor.new("Really black") print( a == "Really black" ) --> false print( a.Name == "Really black" ) --> true !
Since BodyColors.HeadColor (or any of the other ones) return a BrickColor, if we look at this BrickColor's properties, we can see a useful property named Name which returns a string! The string can be used to make a comparison to another string!
BodyColors.HeadColor.Name == "Really black" --if the brickcolor's name of HeadColor is 'Really black' this will be true!
function findTarget() for _, p in pairs(workspace:GetChildren()) do if p:IsA('Model') and not p.Name == "NPCZombie" and not p.Name == "NPCDarkness" and not p:FindFirstChild("Body Colors").HeadColor3 == Color3.new(17, 17, 17) and not p:FindFirstChild("Head").BrickColor == BrickColor.new("Really Black")
this will check all the statements and if its none of them then it will work