【问题标题】:How to do script if key pressed then break out of infinity loop如果按下键然后跳出无限循环,如何执行脚本
【发布时间】:2021-09-20 13:18:29
【问题描述】:
local whenthe = 1

while 3 == 3 do
    wait(0,2)
local v1 = {
    [1] = getrenv()._G.Pass, 
    [2] = "DashTeleport",
    [3] = "True"
}
local rem = game:GetService("ReplicatedStorage").Remotes.SansMoves

rem:InvokeServer(v1) 
end

如何让这个脚本在按下“K”键时中断? 我找了它,但没有找到任何关于它的信息

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    根据this表,K键的代码为107,我们可以将check直接插入循环中,如果key按下则将其中断:

    local UserInputService = game:GetService("UserInputService")
    while 3 == 3 do
        wait(0.2)
        local kHeld = UserInputService:IsKeyDown(107)
        if kHeld then
            break
        end
    end
    

    或者最好不要使用无限条件,如果你真的有一个条件,像这样:

    local UserInputService = game:GetService("UserInputService")
    local kHeld
    while not kHeld do
        wait(0.2)
        kHeld = UserInputService:IsKeyDown(107)
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 2021-03-31
      • 2015-01-29
      相关资源
      最近更新 更多