Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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:

01local guiPopUpEvent = game.ReplicatedStorage.OpenIslandThingyThingThing
02local guiClosedEvent = game.ReplicatedStorage.CloseIslandThingyThingThing
03local islandSwitchGUI = script.Parent
04local click = islandSwitchGUI.Click
05 
06guiPopUpEvent.OnClientEvent:Connect(function(plr)
07    if not islandSwitchGUI.Enabled then
08        islandSwitchGUI.Enabled = true
09 
10        click:Play()
11 
12        spawn(islandSwitchGUI.Close.CloseButton.MouseButton1Click:Wait())
13        spawn(islandSwitchGUI.GO.Button.MouseButton1Click:Wait())
14 
15        -- Continue program
16    end
17end)

I got this error when it ran:

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

(Show&Hide is the script name)

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. Ziffixture 6913 — 4y
0
Simply un enclose the lines from the Spawn functions. Ziffixture 6913 — 4y
0
What do you mean by "un-enclose"? Hoogidy_Boogidy 18 — 4y
0
I don't really know about the spawn function. I just read a little stuff about it and did something. Hoogidy_Boogidy 18 — 4y
View all comments (3 more)
0
Remove the spawn function. Ziffixture 6913 — 4y
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. Hoogidy_Boogidy 18 — 4y
0
I solved it! But thanks for the help! Hoogidy_Boogidy 18 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

I did this:

01local guiPopUpEvent = game.ReplicatedStorage.OpenIslandThingyThingThing
02local guiClosedEvent = game.ReplicatedStorage.CloseIslandThingyThingThing
03local islandSwitchGUI = script.Parent
04local click = islandSwitchGUI.Click
05 
06guiPopUpEvent.OnClientEvent:Connect(function(plr)
07    if not islandSwitchGUI.Enabled then
08        islandSwitchGUI.Enabled = true
09 
10        click:Play()
11 
12        local closed = false
13 
14        while not closed do
15            islandSwitchGUI.Close.CloseButton.MouseButton1Click:Connect(function()
View all 29 lines...

Thanks for trying to help!

Ad
Log in to vote
0
Answered by 4 years ago

Well you should probably learn how to use coroutines.

You can maybe try this:

01-- at the start
02local condition1 = false
03local condition2 = false
04islandSwitchGUI.Close.CloseButton.MouseButton1Click:Connect(function()
05    condition1 = true
06end)
07islandSwitchGUI.GO.Button.MouseButton1Click:Connect(function()
08    condition2 = true
09end)
10 
11-- lines twelve and thirteen, replace with
12repeat wait() until condition1 or condition2
0
Nice! I already solved my question though, but thanks! Hoogidy_Boogidy 18 — 4y
0
I realised once I posted, only five minutes late! radiant_Light203 1166 — 4y

Answer this question