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

How do you write an and statement?

So I am trying make a code execute if both conditions are true. I put a || because that is what you do in java but it does not work. How do you do and statements in lua?

if script.Parent.Parent.Parent.Parent.Parent.Work.Frame.Frame.Slot1.Visible == true || script.Parent.Parent.Parent.Parent.Parent.Work.Frame.Frame.Slot2.Visible == true then

2 comments

1

here is an example: if condition1 == true and condition2 == true then print("both are true") end

1

so basically just write and where you wrote || and , and the could should work fine. Also try to make Variables instead of writing that many Parents, it would make things a bit more organized and easy to understand later on. I hope I solved your problem, esepek.

1 answer

✓ Accepted answer

It is pretty straight-foward, actually, there is a conditional lua statement called and, which stands for both variables that you use. For example, you would do;

if script.Parent.Parent.Parent.Parent.Parent.Work.Frame.Frame.Slot1.Visible == true and script.Parent.Parent.Parent.Parent.Parent.Work.Frame.Frame.Slot2.Visible == true then
	 -- blah blah blah
end

-- or

if condition1 == true and condition2 == true then
	-- blah blah blah
end

Scroll down to Logical Operators here: https://developer.roblox.com/en-us/articles/Conditional-Statements-in-Lua

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