How do I run an anonymous event-triggered function in a coroutine?

  1. What do you want to achieve?

I want several event-triggered functions to be able to run simultaneously in a script. This is an example of one of them:

colBox1.Touched:Connect(function(hit)
-- code using the "hit" parameter
end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried using spawn() and ended up with this:

spawn(colBox1.Touched:Connect(function(hit)
-- code using the "hit" parameter
end))

However, I get an error message saying “attempt to call a RBXScriptConnection value”

1 Like

Touched functions can already be run simultaneously ran in a script though?

2 Likes

I didn’t know that, thank you. Now I feel dumb