Quick coroutine question

Let’s say I have a function onPlayerAdded with player as the parameter.

Usually you’d write something like this:

players.PlayerAdded:Connect(onPlayerAdded)

But if you wanted to wrap it in a coroutine and still have the player parameter passed, would writing it as this still work?

players.PlayerAdded:Connect(coroutine.wrap(onPlayerAdded))

Or, would you have to write it like this (what I’m doing now):

players.PlayerAdded:Connect(function(player)
    coroutine.wrap(onPlayerAdded)(player)
end)
1 Like

would work fine. coroutine.wrap returns a function that forwards the arguments to the wrapped function.

edit: but also this is pointless, the event will already run in its own thread

5 Likes