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

Which way is more efficient for an anonymous coroutine?

So, I have a game where I use coroutines a lot, creating them many many times. Which way would create the least lag? I'm guessing the top one, but idk exactly, am I right?

local cocreate = coroutine.create
local coresume = coroutine.resume

coresume(cocreate(function() --first way
	while wait() do
		print("Test")
	end
end))

or

coroutine.resume(coroutine.create(function() --second way
	while wait() do
		print("Test")
	end
end))

2 comments

1

You won't see a difference. I recommend the first way if you are having to type 'coroutine.create' many times. It will save you time

0

Ok

1 answer

✓ Accepted answer

If you're not using coroutine.yield you do not have a purpose in using coroutine at all.

If you want to just start work in the background, use spawn:

spawn(function()
	while wait() do
		print("Test")
	end
end)

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