I have some parts, each named "Flower", in my model. I put a script in the model to change the colors of the flowers every second. The flowers don't change color, though. The script's code's below. Can anyone help?
local flowers = script.Parent:GetChildren() local colors = {"Bright red", "Bright yellow", "Bright blue", "Bright violet", "Bright bluish green", "Bright orange", "Institutional white" } while true do if flowers.Name == "Flower" then flowers.BrickColor = BrickColor.new(flowers[math.random(#flowers)]) end wait(1) end
You have a few misspells and 1 error!
Fixes
local flowers = script.Parent:GetChildren() local colors = {"Bright red", "Bright yellow", "Bright blue", "Bright violet", "Bright bluish green", "Bright orange", "Institutional white" } while true do for _, flower in pairs (flowers) do -- Loop though all of the children. if flower and flower.Name == "Flower" then -- Use flower for the object, make sure it exists. flower.BrickColor = BrickColor.new(colors[math.random(1, #colors)]) -- Use colors for color. end end wait(1) end
I hope this helped!
Wrong loop. Learn for i, v in pairs(table) do
.
Also, on line 7, you want to look for a random COLOR, not a random flower.
local flowers = script.Parent:GetChildren() local colors = {"Bright red", "Bright yellow", "Bright blue", "Bright violet", "Bright bluish green", "Bright orange", "Institutional white" } for _, v in pairs(flowers) do if flowers.Name == "Flower" then flowers.BrickColor = BrickColor.new(colors[math.random(1, #colors)]) end wait(1) end