Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to fix brickcolor not being changed with a for loop?

Asked by 4 years ago
while true do
if game.Workspace.MaxVal.Value >= 5 then
    local Parts = game.Workspace:GetChildren() 
    for i = 1, #Parts do 
        if Parts[i].Name == "Partay" or "Partay1" or "Partay2" or "Partay3" or "Partay4" or "Partay5" then 
            Parts.BrickColor = BrickColor.new("Parsley green")
        end 
    end 
end
wait(.2)
end

There's no error that's being outputted, but it does go through past that second if statement if I tell it to print something. It might be using the original variable, and not changing it based off of that, but I don't know.

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Problem: BrickColor isn't changing.

Solution: Use Parts[i] instead of Parts on line 06.

Explanation: If you used Parts, the script would add a key called "BrickColor" into the Parts table instead of setting the part's BrickColor. Using Parts[i] would make it so that the BrickColor of the part would change.

while true do
if game.Workspace.MaxVal.Value >= 5 then
    local Parts = game.Workspace:GetChildren() 
    for i = 1, #Parts do 
        if Parts[i].Name == "Partay" or Parts[i].Name == "Partay1" or Parts[i].Name == "Partay2" or Parts[i].Name == "Partay3" or Parts[i].Name == "Partay4" or Parts[i].Name == "Partay5" then 
            Parts[i].BrickColor = BrickColor.new("Parsley green")
        end 
    end 
end
wait(.2)
end

Please upvote and accept this answer if it helped.

0
Yeah, i've tried that before I asked on here. I did it again just to see, and I get the error of "BrickColor is not a valid member of Script" DarkDanny04 407 — 4y
0
Is Partay, Partay1, Partay2, Partay3, Partay4, or Partay5 a script? youtubemasterWOW 2741 — 4y
0
With what I have, I have a code panel thing. Partay are the buttons that are just there, and the other partays with numbers are the ones that actually do something progressive. I named them that just to call them easier in a different script. DarkDanny04 407 — 4y
0
So Partrays are a TextButton? youtubemasterWOW 2741 — 4y
View all comments (2 more)
0
Oh, my bad. By buttons I was talking about their purposes. They are just parts. DarkDanny04 407 — 4y
0
Try it now. I've edited it. youtubemasterWOW 2741 — 4y
Ad

Answer this question