Blinking Light
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 9 of 24.
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)
endThis 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
EasyThe script makes the lamp glow and then dark, so fast that you never see it glow. Make it blink:
- glow (
Neon) for 1 second - then dark (
Plastic) for 1 second - and repeat forever
Press Play to watch it, then Check.
Try it yourself
local lamp = script.Parent
lamp.Material = Enum.Material.Neon
lamp.Material = Enum.Material.Plastic
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Roblox Game Scripting
2Loops and Functions
Row of PillarsStaircase BuilderTower BuilderCoin FactoryBlinking LightVanishing Bridge5Your First Game
Your First ObbyPractice on your own: Online Lua compiler