Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you make an if statement end the script if a condition is met?

Title sort of explains all.

2 answers

You would use a break statement, search it on the wiki for more information.

2 comments

0

Breaks only work with loops and skips through them, I meant something that ends the script entirely.

0

Ends the script entirely? You could just do script.Disabled = true if you wanted

Here's an example, we will be using a BoolValue for this example that has just been changed to true. The script is a child of Boolvalue

script.Parent.Changed:connect(function() -- This just detects a change in a bools value, it does not need to be added.
    if script.Parent.Value == true then -- Replace "script.Parent.Value == true" with your statement.
        print("Condition met") -- Ends the script with a print.
    else
        print("Condition not met") -- If you want to put some code here if the bool does not meet the requirements then do.
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.