It wont let me change only parts with a certain color
local parts = workspace:GetChildren() while true do wait(0) for _, child in pairs(parts) do if child.BrickColor == BrickColor("Really black") then child.BrickColor = BrickColor.new("Really red") end end end
Your script checking every child of Workspace for BrickColor, and when it detects not "Part", error occures, and script disabling, so we need to check, is current child really a part, to prevent error. Also, we need to type BrickColor.new
instead of BrickColor, otherwise it won't work. So, with the following changes, your "If" line will look like that:
if child.ClassName == "Part" and child.BrickColor == BrickColor.new("Really black") then --Code end
You have a few problems. First of all, their is no reason to do wait(0), this will not do anything for you so you would need to do wait()
.
I guess the reason of while true do is so you can continuously have them change? that would seem excessive, if the colors will not change again, then don't run it through an infinite loop.
Also, you're not checking the color correctly on line 5, you still need to use .new, it will NOT change the part because of this, you're using ==
not =
. You will probably have things in your Workspace that are not Parts and will cause an error because they cannot change their color, to fix this we use IsA("ClassName")
, just so you know, some things you may want to change could have a different name such as UnionOperation! Edit this for your own need. Now with the information I provided, here is a script to run once when the game is started, no infinite loop:
local parts = Workspace:GetChildren() for _, child in pairs(parts) do if child.BrickColor == BrickColor.new("Really black") and child:IsA("Part") then child.BrickColor = BrickColor.new("Really red") end end
Now if you want it to do this continuously , then here's the script bellow.
local parts = workspace:GetChildren() while true do wait() -- Very short wait for _, child in pairs(parts) do if child.BrickColor == BrickColor.new("Really black") and child:IsA("Part") then child.BrickColor = BrickColor.new("Really red") end end end