I want to make a for loop wait for an event to fire before executing the code in it again. In the code block below is basically what I want.
1 | for i,v in pairs (t) do |
2 | thing:DoTheThing(v) |
3 | (Wait for event to fire) |
4 | end |
(Note: This isn't the full code, this is only the loop)
In case you're curious or have any alternate solution, this is for pathfinding to a certain location using the pathfinding service.
How would I go about this sort of thing?
Events have a :wait() method which will wait until it fires, then return any parameters.
http://wiki.roblox.com/index.php?title=Event
1 | local Part = workspace.Part |
2 |
3 | local Hit = Part.Touched:wait() |
4 | print (Hit) |
As you've mentioned, you should use it in a loop. The :wait() method does not automatically make a looping occurrence like :connect() does with a function.