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
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.