Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to locate Body Color or BrickColor?

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?

3 comments

0

dont make a new line for the and, the and's go into one straight like

0

can you explain a little better how u want it to work

0

A player will have the body colors of really black and I want this script to identify it from here.

2 answers

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!

4 comments

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"

0

I have tried your method, however the NPC still stands there, I think you misunderstood?

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?

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.

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

1 comment

0

I have tried your correction, however the NPC still does not follow anything now. It just stands still.

This discussion is preserved as it was. New answers, comments, and votes are closed.