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

How can I make a loop (Or any code) wait for an event?

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.

for  i,v in pairs(t) do
	thing:DoTheThing(v)
	(Wait for event to fire)
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?

1 answer

✓ Accepted answer

Events have a :wait() method which will wait until it fires, then return any parameters.

http://wiki.roblox.com/index.php?title=Event

local Part = workspace.Part

local Hit = Part.Touched:wait()
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.

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