local Co1 = "Navy blue"
local Co2 = "Lily white"
for i,v in pairs(game.Workspace:GetChildren()) do
if v:IsA("Part") and v.Name == "Color1" then
v.BrickColor == BrickColor.new(Co1)
end
end
for i,v in pairs(game.Workspace:GetChildren()) do
if v:IsA("Part") and v.Name == "Color2" then
v.BrickColor == BrickColor.new(Co2)
end
end
Their were 4 problems that I noticed.
Firstly, you were looking for v.Name, and so it was looking for a string. I put "" around Color1 and Color2 to make it a string.
Secondly, with BrickColor, you don't go BrickColor.new = (), as BrickColor is just BrickColor.new() and inside those brackets is where you have your color.
Thirdly, you only had 1 =. When comparing something, or checking it in an if statement, you must have ==
Finally, in the for loop, you weren't looking for anything. I am guessing you are checking the children of Workspace, so I used game.Workspace:GetChildren() to get the children of Workspace, and so then the script can continue running to look for a part with the certain name.
With that last little bit, if you ARE checking for parts in the Workspace, then you can make this code a lot shorter and less cluttered
local Co1 = "Navy blue"
local Co2 = "Lily white"
for i,v in pairs(game.Workspace:GetChildren()) do
if v:IsA("Part") then
if v.Name == "Color1" then
v.BrickColor == BrickColor.new(Co1)
elseif v.Name == "Color2" then
v.BrickColor = BrickColor.new(Co2)
end
end
end
What I did was check the v:IsA("Part") first, as you don't need to repeat it. It then checks for the parts. Doing this is not technically necessary, but it just makes your code a lot easier to read and if you ever work with other developers, they can help edit your code, and they can see what's going on where.
Hope this helped and be sure to accept answer and +1
If their are any errors from this, please reply to this answer with anything in the output, or edit your answer with what you have and the output.
5 comments
Doesnt work
23:40:39.799 - Workspace.Script:6: 'then' expected near '=' < Output
Add an = sign to the "if v.Name = "Color1" then", it should be "if v.Name == "Color1" then"
Editted with what should work
Works!