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

How do I check if a statement is true, then continue the scripts?

Is there a way to check something and if it’s false, then completely ignore the line of code and continue with the scripts below it, and if it’s true then run that line of code along with the ones below it.

3 comments

0

if statements

0

You just defined an if statement perfectly, Sorukan.

0

if true then

1 answer

✓ Accepted answer

##Question

How do I check if a statement is true, then continue the scripts?

##Answer Yes most certainly Like almost every programming language, lua has a system for conditionals. In lua you can check for a condition and run the code inside the scope of the block.

(hey if this helped you should click "accept answer")

###Example Code

if (condition1) then
	print"a"
	--// runs if condition1 is true
elseif (condition2) then
	print"b"
	--// runs if condition2 is true but not if condition1 was true
else
	print"c"
	--// runs if no other conditions worked
end

print"d"
--// runs eitherway since its outside the scope of the if statement

###More Specific Example

Is there a way to check something and if it’s false, then completely ignore the line of code and continue with the scripts below it, and if it’s true then run that line of code along with the ones below it.

Yes there certainly is just put your code in a if statement or a function that is called if the statement is true.

local function wasTrue()
	--// some code
end

local function wasFalse()
	--// some other code
end

if (condition) then
	wasTrue()
else
	wasFalse()
end

1 comment

0

Note that you do not need "()" around conditions in Lua. ex, "if condition1 then" works just fine. Also, a note for anyone new to Lua: saying print"a" is a shortcut for print("a") -- this works for any function where you only want to send a single string as an argument (you can also send new tables this way).

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