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

How do you wait for one function of two functions to fire?

I searched this question on google, but instead, showed me how to FIRE multiple functions and not WAIT for multiple functions to fire.

My goal is to see if a function fired out of two functions. If both functions fired at the same time somehow, then it will continue the program. If one function fires, but not the other, then it will continue the program. If no functions fire, then keep waiting for one of them to fire.

Here's the code:

local guiPopUpEvent = game.ReplicatedStorage.OpenIslandThingyThingThing
local guiClosedEvent = game.ReplicatedStorage.CloseIslandThingyThingThing
local islandSwitchGUI = script.Parent
local click = islandSwitchGUI.Click

guiPopUpEvent.OnClientEvent:Connect(function(plr)
	if not islandSwitchGUI.Enabled then
		islandSwitchGUI.Enabled = true
		
		click:Play()
		
		spawn(islandSwitchGUI.Close.CloseButton.MouseButton1Click:Wait())
		spawn(islandSwitchGUI.GO.Button.MouseButton1Click:Wait())
		
		-- Continue program
	end
end)

I got this error when it ran:

Spawn function requires 1 argument - Client - Show&Hide:12

(Show&Hide is the script name)

7 comments

0

Spawn will open a new thread to execute the passed function as a Callback. 'MouseButton1Click' is an RBXScriptSignal, which you've called the 'Wait' method on to yield for results. That was already appropriate.

0

Simply un enclose the lines from the Spawn functions.

0

What do you mean by "un-enclose"?

0

I don't really know about the spawn function. I just read a little stuff about it and did something.

0

Remove the spawn function.

0

Removing the spawn function will make it wait for both functions to fire, but I want it to wait for ONE function to fire, not two.

0

I solved it! But thanks for the help!

2 answers

I did this:

local guiPopUpEvent = game.ReplicatedStorage.OpenIslandThingyThingThing
local guiClosedEvent = game.ReplicatedStorage.CloseIslandThingyThingThing
local islandSwitchGUI = script.Parent
local click = islandSwitchGUI.Click

guiPopUpEvent.OnClientEvent:Connect(function(plr)
	if not islandSwitchGUI.Enabled then
		islandSwitchGUI.Enabled = true
		
		click:Play()
		
		local closed = false
		
		while not closed do
			islandSwitchGUI.Close.CloseButton.MouseButton1Click:Connect(function()
				closed = true
			end)
			
			if not closed then
				islandSwitchGUI.GO.Button.MouseButton1Click:Connect(function()
					closed = true
				end)
			end
			wait()
		end
		
		-- Continue program
	end
end)

Thanks for trying to help!

Well you should probably learn how to use coroutines.

You can maybe try this:

-- at the start
local condition1 = false
local condition2 = false
islandSwitchGUI.Close.CloseButton.MouseButton1Click:Connect(function()
	condition1 = true
end)
islandSwitchGUI.GO.Button.MouseButton1Click:Connect(function()
	condition2 = true
end)

-- lines twelve and thirteen, replace with
repeat wait() until condition1 or condition2

2 comments

0

Nice! I already solved my question though, but thanks!

0

I realised once I posted, only five minutes late!

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