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
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
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
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.