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

Help With Nested Functions?

Asked by 10 years ago

I have been trying to figure out a way to have nested functions in my script. I need both gui1 and gui2 to make gui3 visible when they click the button on each and then I need it to connect to the function when the player clicks on gui3. The problem I am having is if the player clicks gui1, then gui3, then gui2, clicking gui3 again would cause both events within the functions to fire and print both options at the same time. I need to figure out a way to fix this and the only way that I can think of is debounce. I just wanted to know if there was an easier way.

This is the code that I have so far and it does what is described above.

gui1.MouseButton1Down:connect(function()
    gui3.Visible = true
    gui3.MouseButton1Down:connect(function()
        print("Option1")
        gui3.Visible = false
    end)
end)

gui2.MouseButton1Down:connect(function()
    gui3.Visible = true
    gui3.MouseButton1Down:connect(function()
        print("Option2")
        gui3.Visible = false
    end)
end)

1 answer

Log in to vote
0
Answered by 10 years ago

I believe you should make the second one invisible so you can't click it, and make them the other type of functions. For example,

selected="2"
function guiUno()
    if selected=="2" then
        g2:disconnect()
        selected="1"
        guiTres()
    elseif selected=="1" or selected=="0" then
        gui3.Visible=true
        selected="1"
        guiTres()
    end
end

function guiDos()
    if selected=="1" then
        g1:disconnect()
        selected="2"
        guiTres()
    elseif selected=="2" or selected=="0" then
        gui3.Visible=true
        selected="2"
        guiTres()
    end
end

function guiTres()
    if selected=="1" then
        print("Option1")
    elseif selected=="2" then
        print("Option2")
    end
end

g1=gui1.MouseButton1Down:connect(guiUno)
g2=gui2.MouseButton1Down:connect(guiDos)
Ad

Answer this question