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

Is there a way to make this code possibly shorter?

Asked by
oSyM8V3N 429 Moderation Voter
6 years ago
    for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
    end

    wait(1)

        for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency + .1
        end

        wait(1)

        for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
    end

wait(1)

        for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency +.1
    end

wait(1)

        for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
    end
0
use the i parameter stop wasting your computer's resources wasting calculations on the i parameter already hiimgoodpack 2009 — 6y

1 answer

Log in to vote
1
Answered by
Mayk728 855 Moderation Voter
6 years ago
Edited 6 years ago

Sure! Just use a while loop. This will keep it going forever,

while true do
    for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
    end
    wait(1)
    for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency + .1
    end
end

To keep it looping a certain amount of times, just create a value and make it increase after each loop.

local LoopBreak = 0
while true do
    if LoopBreak == 5 then --Once the LoopBreak reaches 5, it will break the loop.
        break
    end
    for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency - .1
    end
    wait(1)
    for i = 1, 10 do
        wait(0.01)
        pMenu.loading.ImageTransparency = pMenu.loading.ImageTransparency + .1
    end
    LoopBreak = LoopBreak + 1 --Increases the value by one everytime it loops.
end
0
Thanks, this is perfect. But how would i make it loop for about 5 times? oSyM8V3N 429 — 6y
0
I'll edit the question for ya. Mayk728 855 — 6y
0
K thanks oSyM8V3N 429 — 6y
0
Alright Thanks For Helping :) oSyM8V3N 429 — 6y
Ad

Answer this question