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

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

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

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!

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