'I am really new at coding and I am coding in lua a script for a part, I want the color to change every second

local color = 1
while color < 5 do
game.Workspace.Part_multicolor.BrickColor = BrickColor.Red()
wait(1)
game.Workspace.Part_multicolor.BrickColor = BrickColor.Blue()
end

This is the code, I put a variable that its value its 1, then i put a loop that repeats forever and change between red and blue each second.



Solution 1:[1]

If you want the color change every seconds you need one more "wait(1)"

local color = 1
while color < 5 do
 game.Workspace.Part_multicolor.BrickColor = BrickColor.Red()
 wait(1)
 game.Workspace.Part_multicolor.BrickColor = BrickColor.Blue()
 wait(1) --here add a wait(1)
end

the loop will wait 1 seconds after each change

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John