Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How come this wont loop?

Asked by 8 years ago

I looped it but it wont loop.

script.Parent.Decal.Transparency = 0
wait(5)
script.Parent.Decal.Transparency = 1
script.Parent.Decal1.Transparency = 0
wait(5)
script.Parent.Decal1.Transparency = 1
script.Parent.Decal2.Transparency = 0
wait(5)
script.Parent.Decal2.Transparency = 1
script.Parent.Decal3.Transparency = 0
wait(5)
script.Parent.Decal3.Transparency = 1

looped = true
0
This is not how loops work at all, please read the wiki. Ryzox 220 — 8y

1 answer

Log in to vote
2
Answered by
yelsew 205 Moderation Voter
8 years ago

What is a loop?

A loop is a block of code that will run indefinitely unless told to stop.

What kind of loops are there?

There are 3 main types of loops. For, While, and Repeat. Each of them work very differently.

For

A For loop is a loop that will loop a defined amount of times. There a quite a few different ways to do this, which is why I recommend looking at the wiki. For example:

for i = 1, 10 do
    print("This is the for loop")
    wait()
end

While

A While loop is a loop that will run indefinitely, until told to stop. The ways to stop a while loop are either to make it a variable loop or break it. And you always need a wait() function. Example:

local whilebool = true
local changepart = game.Workspace.Part

while whilebool do
    print("lol")
    if changepart.Changed then
        break
    end
    wait(1)
end

Repeat A Repeat loop is a loop that will run until a condition is met. This is particularly useful when seeing if a LocalPlayer is there. The following example must be in a LocalScript.

local players = game:GetService("Players")

repeat wait() until players.LocalPlayer

local player = players.LocalPlayer

Pros and Cons of Loops

Loops are very efficient ways of indexing tables, counting up or down, or smoothly CFraming. They also minimize code, so you can do more with less.

Loops are also very resource consuming, depending on the loop. Do not ever do a loop without a wait() inside. This can cause studio to crash, and make you lose your hard work.

Ad

Answer this question