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

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

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

✓ Accepted answer

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.

6 comments

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"

0

Is Partay, Partay1, Partay2, Partay3, Partay4, or Partay5 a script?

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.

0

So Partrays are a TextButton?

0

Oh, my bad. By buttons I was talking about their purposes. They are just parts.

0

Try it now. I've edited it.

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