Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make flashing lights with on and off switch?

I want to make a flashing pointlight but I want to also have an On and Off switch with it. Coding:

local light = game.Workspace.LightBulb.Pointlight

while true do
         light.enabled = false
         light.enabled = true
         wait (0.2)
         light.enabled = true
end 

Please reply ASAP. Thanks.

1 answer

✓ Accepted answer

Make sure you put a Click Detector inside a part you will be using, and put the following code inside your script:

light = game.Workspace.LightBulb.Pointlight -- Light directory
cd = script.Parent.ClickDetector -- Click Detector
on=false

cd.MouseClick:connect(function()
if on == false then
on = true
else
on = false
end
end)

while wait() do
if on then
light.Enabled = false
wait(0.2)
light.Enabled = true
wait(0.2)
light.Enabled = true
else
light.Enabled = false
end 
end

Make sure to comment if what I gave you isn't what you needed.

3 comments

0

Please indent properly.

0

And you can simpligy lines 6-10 by just saying "on = not on".

0

Why do you have line 19? light is already enabled.

This discussion is preserved as it was. New answers, comments, and votes are closed.