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

How to make 2 For i loops run at the same time?

Asked by 6 years ago

I have a for i loop for size and a for i loop for transparency which are suppose to happen at the same time but instead it does size first then transparency.

Run = game:GetService('RunService')

for i = 1,20,.1 do
    Run.Stepped:wait()
    part.Size = Vector3.new(i,i,i)
end

for i = 0,1,.1 do
    Run.Stepped:wait()
    part.Transparency = i
end

1 answer

Log in to vote
1
Answered by 6 years ago

You can use coroutines like so.

Run = game:GetService('RunService')

local taska = coroutine.wrap(function()
    for i = 1,20,.1 do
        Run.Stepped:wait()
        part.Size = Vector3.new(i,i,i)
    end
end)

taska()

local taskb = coroutine.wrap(function()
    for i = 0,1,.1 do
        Run.Stepped:wait()
        part.Transparency = i
    end
end)

taskb()

Coroutines make code run simultaneously, plus some cool stuff. Hope this helps!

Ad

Answer this question