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

Help with If Statements?

This script works perfectly fine if I remove the

and v.BrickColor == "Bright red" 

but if I don't it won't print out v and yes I have a part colored Bright red.Why won't it print out v?

I got no errors

Script:

for i,v in pairs (game.Workspace:GetChildren()) do
if v:IsA("Part") and v.BrickColor == "Bright red" 
	then 
	print(v)
 end 
end

1 answer

✓ Accepted answer

The primary problem is that the BrickColor is not a string.

You try and compare BrickColor with the string 'Bright red'.

There are multiple solutions to this issue -

• you can call tostring() on the BrickColor property, resulting in a string.

for i,v in pairs (game.Workspace:GetChildren()) do
if v:IsA("Part") and tostring(v.BrickColor) == "Bright red" 
    then 
    print(v)
 end 
end

• you can access the BrickColor datatype when comparing (recommended)

for i,v in pairs (game.Workspace:GetChildren()) do
if v:IsA("Part") and v.BrickColor == BrickColor.new("Bright red")
    then 
    print(v)
 end 
end

You can read more about this method here.

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