【问题标题】:LUA - How to stop a script from runningLUA - 如何阻止脚本运行
【发布时间】:2021-12-28 00:34:18
【问题描述】:

您好,我正在制作一个 roblox LUA 脚本,但我不知道如何让脚本在 if 语句后停止。这是我的代码。

if not newPlayer:GetRankInGroup(workspace.CoreValues.GroupID.Value) then
    teamName = "Civilian"
    (STOP)
end

【问题讨论】:

  • 嗨,也许是os.exit
  • 它能在 roblox 上工作吗?
  • 我对此表示怀疑,但知道会发生什么会很有趣

标签: lua roblox


【解决方案1】:

根据您构建代码的方式,您可以简单地return

local shouldEscape = true
if shouldEscape then
    return
end
print("This line won't get hit")

但是,如果您设置了事件侦听器,这不会阻止它们触发。您需要清理它们、禁用脚本或删除脚本。

-- connect to a signal as an example
local connection = game.Players.PlayerAdded:Connect(function(player)
    -- if the Script is still enabled, this line will print
    print("Player Added : " .. player.Name)
end

local shouldEscape = true
if shouldEscape then
    -- disable the script
    script.Disabled = true

    -- OR : disconnect the signals
    --connection:Disconnect()

    -- OR : delete the script entirely
    --script:Destroy()

    -- escape so that no other lines execute
    return
end
print("This line won't get hit")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多