Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

2 comments

0

Thank you! It works now.

1

Please mark the answer as accepted

This discussion is preserved as it was. New answers, comments, and votes are closed.