First forum post, so please excuse me if there are any weird problems with this post.
As title states, I have two buttons, and I need to pause the script until either one of them is clicked. I know about using :Wait() to pause until the event is fired, but the button that is clicked is up to the player and I can’t predict which one they’ll press.
I believe :Wait() might not be the best choice for this situation. Might need to explain more with your goals for this project but it seems you want to have a function called when these buttons are pressed using :Connect(). This I presume would not cause the issues you are experiencing? Will need more information to confirm.
No, I have two buttons: 1 and 2.
I need the script to pause and wait until EITHER ONE of the buttons are clicked, and then continue.
Is there any way to do that?
Do you by chance have any existing code? At least with my thought process would to have either button link back to one function could advance whatever needs to occur.
Although logically you would think to use :Wait() it usually isn’t the ideal solution in most situations because it holds up the entire script from preforming any other actions. Which might come to be an issue later if you expand your code.
local buttons = {btn1, btn2}
local clicked = false
for _, v in ipairs(buttons) do
v.MouseButton1Click:Connect(function()
clicked = true
end)
end
repeat task.wait() until clicked
-- this will execute after one of the buttons is clicked
local button1 = ... -- your button
local button2 = ... -- your other button
local continue = false
button1.MouseButton1Click:Connect(function()
continue = true
end)
button2.MouseButton1Click:Connect(function()
continue = true
end)
-- main bit
print("Hello click a button to continue...")
repeat wait() until continue
continue = false
print("Continue...")
repeat wait() until continue
continue = false
You can do this as much times as you want, instead of only once.