LUA - 如何从 运行 停止脚本

LUA - How to stop a script from running

你好,我正在制作一个 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")