Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LUA - How to stop a script from running

Tags:

lua

roblox

I am making a Roblox LUA script, and I can't figure out how to make the script stop after an if statement.

if not newPlayer:GetRankInGroup(workspace.CoreValues.GroupID.Value) then
    teamName = "Civilian"
    (STOP)
end
like image 960
Felix Avatar asked Dec 06 '25 18:12

Felix


1 Answers

Depending on how you structure your code, you could simply return.

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

But if you have set up event listeners, this won't stop those from firing. You'll need to clean those up, disable the Script, or delete the Script.

-- 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")
like image 58
Kylaaa Avatar answered Dec 08 '25 07:12

Kylaaa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!