使用 :connect 使用 if 条件中断函数

问题描述 投票:0回答:0

我正在尝试使用布尔变量 enterFinished 在 enter.MouseClick:connect() 完成后跳出功能键盘。

function keypad(state)
    local enterFinished = false
     enter.MouseClick:Connect(function()
        if state == "unlock" then
            enterPressed = true
            local x = keyPressed(input)
            enterPressed = false
            table.clear(input)
            if x == pin then
                atmScreen.Text = ("Pin Correct!")
                enterFinished = true
            else
                atmScreen.Text = ("Pin Incorrect! Please reenter pin!")
            end
        elseif state == "choice" then
            print("choice")
        end
    end)    
    for i, v in pairs(folder:GetChildren()) do
        if enterFinished == true then
            print(enterFinished)
            return(nil)
        end 
        v.ClickDetector.MouseClick:Connect(function()
            table.insert(input,i)
            keyPressed(input)
        end)
    end
end

if 条件只运行一次,每当我尝试将其放入循环中时,代码就会崩溃或不起作用。

function loops lua roblox
© www.soinside.com 2019 - 2024. All rights reserved.