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

BrickColor is not a valid member of Script for Dance Floor?

For a self mini-project on while loops and in loops, I decided to script a dance floor today. The problem I noticed right away was the colors, which are randomly assigned from a local list of picked colors, changed once and is like that for the rest of the testing. What I'm trying to do is have the colors change every 0.75 seconds.

I noticed in the output browser it says BrickColor is not a valid member of the script which I quite don't understand since I'm a beginner. Would love to know those type of errors exactly mean. Thanks.

Here is the code:

local colors = {"Bright red","Bright blue","Bright green"}
local max = table.getn(colors)

while wait(0.75) do
	for _, v in pairs(game.Workspace.DanceFloor.Lights:GetChildren()) do
		v.BrickColor = BrickColor.new(colors[math.random(1,max)])
	end
end

3 answers

✓ Accepted answer

Use Instance:IsA() to check if v is a basepart(Part, union, or meshpart) and if so, change it's brickcolor. Your code was erroring because there is an object in Lights that wasn't a part, meaning you can't change its brickcolor.

local colors = {"Bright red","Bright blue","Bright green"}
local max = table.getn(colors)

while wait(0.75) do
    for _, v in pairs(game.Workspace.DanceFloor.Lights:GetChildren()) do
	if v:IsA("BasePart") then --check if v is a basepart
       	     v.BrickColor = BrickColor.new(colors[math.random(1,max)])
	end
    end
end

1 comment

0

That was interesting since in the lights model, there were only parts, but this solution worked flawlessly

Try doing this.

while true do
	wait(0.75)
	for _, v in pairs(game.Workspace.DanceFloor.Lights:GetChildren()) do
		v.BrickColor = BrickColor.new(colors[math.random(1,max)])
	end
end

3 comments

0

It should loop it forever

0

I tried it, but it still gives me the same error with "BrickColor is not a valid member of Script" in output

0

Check the other person sent a script, try theirs.

while true do
script.Parent.Color = Color3.new(math.random(), math.random(), math.random())
wait(0.5)
end

This is a really old script, but it works like a charm. Make sure that its a server script and is in every part you want to change color in.

3 comments

0

Yeah that's another way you can do it, put a script in every block

0

This worked fine, but the goal I had in mind for this mini-project was to use a list of picked colors and have that randomly assigned to each brick in a in pair loop

0

you can change the "math.random()" to your color

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