Wait until a function stops running

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am making a round system for my comedy game show game.

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know if it’s possible to wait until the function has stopped running. I wouldn’t consider using wait() because when I change the round system a bit I don’t know how long it lasts.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tried using wait() normally but it just didn’t work very well considering my function ends at some defined times.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local function round()
	local selectedPlayer1 = nil
	local selectedPlayer2 = nil
	for i = 30, 0, -1 do
		game.ReplicatedStorage.RoundStatus.Value = "Intermission: "..tostring(i)
		wait(1)
	end
	wait(1)
	game.ReplicatedStorage.RoundStatus.Value = "The contestants are..."
	wait(5)
	local players = game.Players:GetChildren()
	selectedPlayer1 = players[math.random(1, #players)].Name
	selectedPlayer2 = players[math.random(1, #players)].Name
	if #players < 1 then
		game.ReplicatedStorage.RoundStatus.Value = "Not enough players to begin."
		wait(2)
		return
	end
	if selectedPlayer2 == selectedPlayer1 then
		selectedPlayer2 = players[math.random(1, #players)].Name
		repeat wait() until selectedPlayer2 ~= selectedPlayer1

	end
	game.ReplicatedStorage.RoundStatus.Value = selectedPlayer1.." and "..selectedPlayer2
	wait(3)
end

while true do
	round()
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

A code will yield until a called function is finished

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