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

How do I simultaneously run a for loop?

Asked by 6 years ago

For example, if I want a brick to levitate and change it's transparency at the same time. I put this.

for i = 1,200 do brick.CFrame = brick.CFrame*CFrame.new(.1,.1,0) wait() end

for transparency = 0,1,.1 do script.Parent.Transparency = transparency wait(.1) end

But what it does is levitate the brick first, and then change it's transparency once it's reached it's final position.

Any help is appreciated.

2 answers

Log in to vote
2
Answered by 6 years ago

You should just put them both in the same for loop:

for i = 1,200 do 
wait() 
brick.CFrame = script.Parent.CFrame*CFrame.new(.1,.1,0) 
brick.Transparency = script.Parent.Transparency + 0.01
end

Ad
Log in to vote
1
Answered by 6 years ago

If merging for loops doesn't work (as roblox99456789 demonstrates), perhaps because the for loops wait different amounts of time or go on for different total lengths of time, use coroutines:

coroutine.resume(coroutine.create(function()
-- for loop #1 here
end))
-- for loop #2 here.
0
can be as effective as a merging abnotaddable 920 — 6y

Answer this question