How do I shorten the way of using an if statement?

How do I shorten the way of using an if statement?

So I’ve seen people do this for example:

local humanoid = character and character:FindFirstChild("Humanoid")

But I don’t know what it means and I don’t understand how to use it in my code?

Here is my code:

if lastPart then
		lastPart.BillboardGui.Enabled = false
	end

And I’m pretty sure you can turn it into one of those shorter versions of an if statement but I don’t know how.

You can shorten it by Assigning Enabled with a conditional statement, lets say you wanted to ensure 4 == 4 which a variable, instead of checking a condition and then assigning a true or false value, you can say this:

local Is4 = (4 == 4) -- This will return a Boolean
-- it is also how if statements function

print(Is4) -- true

for this example, you can say:

lastPart.BillboardGui.Enabled = (lastpart == nil)

You can also use this for and, and or

local Confirmation = Is4 and true or false
-- if Is4 is true then value will be true, otherwise it will be given
-- the value of false

local Another = lastpart or 0
-- if lastPart doesnt exist, 0 will be assigned

You can also say this

local boolean = if Condition then true else false

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.