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 3 years ago
Edited 3 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:

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)

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

2 answers

Log in to vote
0
Answered by 3 years ago

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!

Ad
Log in to vote
0
Answered by 3 years ago

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
0
Nice! I already solved my question though, but thanks! Hoogidy_Boogidy 18 — 3y
0
I realised once I posted, only five minutes late! radiant_Light203 1166 — 3y

Answer this question