Menu
CoddyTech

Blinking Light

Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 9 of 25.

Change a part twice in a row and you only ever see the second change: the script runs both lines in an instant. task.wait(seconds) pauses the script in between, while the rest of the game keeps running:

print("Ready")
task.wait(3)
print("Go!")

Go! appears 3 seconds after Ready.

To repeat something forever, use a while true do loop. It runs its body, then starts over:

local sign = script.Parent
while true do
	sign.Color = Color3.fromRGB(255, 0, 0)
	task.wait(0.5)
	sign.Color = Color3.fromRGB(0, 0, 255)
	task.wait(0.5)
end

This sign flashes red and blue every half second. A while true loop must contain a task.wait: without one it never lets the game continue, and Roblox stops the script with a timeout error.

challenge icon

Challenge

Easy

Make the lamp blink: the script switches it so fast that you never see it glow.

  1. Add task.wait(1) after the Neon line and after the Plastic line.
  2. Wrap all four lines in while true do ... end.

Press Play: the lamp glows for 1 second, then goes dark for 1 second, over and over. Then Check.

Try it yourself

local lamp = script.Parent

lamp.Material = Enum.Material.Neon
lamp.Material = Enum.Material.Plastic

All lessons in Roblox Game Scripting

Practice on your own: Online Lua compiler