Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do you write an and statement?

Asked by 3 years ago

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

1
here is an example: if condition1 == true and condition2 == true then print("both are true") end esepek 103 — 3y
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. esepek 103 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

Ad

Answer this question