LUA - 如何停止脚本运行

标签 lua roblox

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

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

最佳答案

根据您构建代码的方式,您可以简单地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")

关于LUA - 如何停止脚本运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69997500/

相关文章:

lua内存管理

c# - 如何将值添加到数组

lua - 表字段中的变量名不起作用

oop - 对象如何在Lua中引用自身?

user-interface - 为什么CoreGui RobloxLocked 在DataModel 中,为什么可信用户不能使用CoreScripts?

c++ - 如何使用 C++ 语言的 Web API?

lua - 如何在 Lua 中结束循环协程?

performance - gslshell(基于 lua)返回 0/0 ==0/0 true

c++ - Xbox360 模拟摇杆角度 SDL

audio - 在 Roblox 上本地播放音乐