Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to locate Body Color or BrickColor?

Asked by 5 years ago
Edited 5 years ago

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?

0
dont make a new line for the and, the and's go into one straight like Gameplayer365247v2 1055 — 5y
0
can you explain a little better how u want it to work Gameplayer365247v2 1055 — 5y
0
A player will have the body colors of really black and I want this script to identify it from here. Bgonzalezseeya11 27 — 5y

2 answers

Log in to vote
0
Answered by
pidgey 548 Moderation Voter
5 years ago
Edited 5 years ago

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!
0
the players skin can be "Really black" and he wants the npc to ignore them if i understand correctly so hes doing it partialy right but he shouldnt do ~= 'Really black' instead he should do as you should == "Really black" Gameplayer365247v2 1055 — 5y
0
I have tried your method, however the NPC still stands there, I think you misunderstood? Bgonzalezseeya11 27 — 5y
0
If that is actually your full code, it has a bunch of syntax errors. Op, are you getting any errors in output that you can provide? pidgey 548 — 5y
0
The code without the "--p:FindFirstChild," etc works fine and ignores the models completely however as soon as I add the code trying to find body colors it breaks. Bgonzalezseeya11 27 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
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

0
I have tried your correction, however the NPC still does not follow anything now. It just stands still. Bgonzalezseeya11 27 — 5y

Answer this question