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

How do I make a script repeat itself?

I have tried making a blinking light and i did everything I could. I was told to do "While true do" then my code and "wait(0.01)" so it wouldn't crash. here is what it looks like:

while true do game.Workspace.BlinkingLight.pointLight.Enabled = true game.Workspace.BlinkingLight.pointLight.Enabled = false wait(0.01)

It never worked.

2 answers

You missed an end at the end of your script. You will want to open the Output and Script Analysis windows so that Roblox can tell you about these errors.

Also, when writing a question or answer, be sure to use the Lua button to wrap your code in a code block (right-most button near the Bold/Italic buttons).

Finally, note that you can just do wait() to wait as little as possible. Roblox will wait for approximately 0.03 seconds (but it varies a bit).

As lukeb50 points out, you also need 2 wait()s to see any effect -- one after each change to the light.

Your wait() is after you change the light both times. You want to wait between enabling and disabling the light so the effect is visible, and wait a little longer as .01 is too fast for anyone to notice.

Try this:

while true do 
	game.Workspace.BlinkingLight.pointLight.Enabled = true
	wait(0.5)
	game.Workspace.BlinkingLight.pointLight.Enabled = false
	wait(0.5)
end

Adjust the wait to speed it up or slow it down

1 comment

0

Minor: you would see the effect with just "wait()", though I agree 0.5 is more reasonable.

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