Events firing in a while loop all at once (no wait in between)

Hello, I have another question on something I am confused on.

I’m looking to make rounds for a musical chairs game using a while loop, but I am using bindable events to grab other script’s code inside the while loop. When I play the game, there is no wait period in between each bindable function being called. I’m confused because I don’t see how I can fix AND I can’t add waits because I need to wait for the entire code in each event to finish!!!

Here is what one of the functions in the while loop are like: (All of them are the same pretty much, just calling different bindable events)

function WaitForPlayers()
	Events.WaitForPlayers:Fire(Players, Status, Teams, Remotes, GameSpawn, DefaultMusicIds, CustomMusicIds, SeatedPlrs, playersInGame, Stage)

Here is the while loop:

local Active = false
function StartRoutine()
	Active = false

while true do
	if Active == false then
		Active = true

All I really need to know is if there is some way to pause the loop until an event finishes? Thanks for any help.

You could use a BindableFunction. When a BindableFunction is invoked, it will yield until a result is returned. You can pass arguments with a BindableFunction just like a BindableEvent, but they just yield until a value(s) is returned. There are some tutorials as well on how to use them.

1 Like

BindableEvent is asynchronous, use BindableFunction (or better, ModuleScripts)

1 Like