How to pause a loop until an event is fired

Hi! ^^

I’m trying to create a game loop that chooses a game, triggers another script that handles the chosen game, and continues the main game loop when that script is done. But I can’t figure out how to pause the main loop until the event is fired. How would I do this?

If that doesn’t make sense, I’m basically trying to pause a loop until a certain event is fired. lol

All help is very appreciated!

i think using the RemoteEvent:Wait() works for this. i may be wrong as i dont use :Wait() much.
yeah i think it yields the code until the event is connected

I’m trying to receive a variable from the event, is it possible to receive that information with Event:Wait() ?

use RemoteEvent:Wait(), or if you wanna do it more complicated you can just have it with a repeat loop and then a actor sends data saying when it fired, but thats a waste of time, so yeah. RemoteEvent:Wait()

In Roblox, RBXScriptSignals (Events) have a :Wait method, which stops the current script until the event has been fired. When the event was fired, the script continues, and provides the values it was given.

local a = Event:Wait() -- Stops and returns the values if fired
2 Likes

i think so? i think you simply need to local variable it

So the “a” variable will contain the values?

It depends on how many values it returned. If it returned two values, you use two variables.

local a, b = Event:Wait()

Ok worddd

I’ll try this out rq

Okok wordddd this worked! Tysm bro :handshake:

1 Like

Hey buddy, if another spawn() exists the script ,it will take place what

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.