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

[ANSWERED]How to make it wait until the button pressed to run the loop but do it in the amount func?

Asked by 4 years ago
Edited 4 years ago

I am making an admin and I want to know how I can make it wait to run the code when the user presses ok.

function amount()
    script.Parent.Parent.amount.Visible = true
    script.Parent.Parent.amount.OK.MouseButton1Click:Connect(function()
        script.Parent.Parent.amount.Visible = false
        number = tonumber(script.Parent.Parent.amount.input.Text)
    end)
end

function commands()
    local cmd = script.Parent.Parent.bar.Text
    if cmd == "cmds" then
        print("commands: \n cmds \n test")
    elseif cmd == "test" then
        amount()
        for i=1,number do
            print("hi")
            wait(0)
        end
    end
end

script.Parent.MouseButton1Click:Connect(commands)

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago

Hello, zymletal!

You can use :Wait() to make the script wait for the function to be triggered

function amount()
    script.Parent.Parent.amount.Visible = true
    script.Parent.Parent.amount.OK.MouseButton1Click:Wait() --Waits for the button to be pressed
    script.Parent.Parent.amount.Visible = false
    number = tonumber(script.Parent.Parent.amount.input.Text)
end

function commands()
    local cmd = script.Parent.Parent.bar.Text
    if cmd == "cmds" then
        print("commands: \n cmds \n test")
    elseif cmd == "test" then
        amount()
        for i=1,number do
            print("hi")
            wait(0)
        end
    end
end

script.Parent.MouseButton1Click:Connect(commands)
0
Thank you! It works now. zymletal 37 — 4y
1
Please mark the answer as accepted Leamir 3138 — 4y
Ad

Answer this question