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

Where should i place "and" and how use it?

Asked by 6 years ago

I have that script, but i dont know how and where place and. I want that, If Light.Value ==1 AND if V (IntValue) == 1 then script.Parent.Base.PointLight2.Range = 18 script.Parent.Humanoid.WalkSpeed = 30

01local Player = game:GetService("Players").LocalPlayer
02local stats = Player:WaitForChild("leaderstats")
03local Light = Player.leaderstats.Light
04 
05while true do
06if script.Parent.V.Value == 1
07    and
08    if Light.Value ==1 then
09 
10script.Parent.Base.PointLight2.Range = 18
11script.Parent.Humanoid.WalkSpeed = 30
12 
13end
14 
15end
2
if script.Parent.V.Value == 1 and Light.Value == 1 then Rare_tendo 3000 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago

You can use and in a singular if statement like so...

1if condition and condition2 then
2    ...
3end

In your case...

1if script.Parent.V.Value == 1 and Light.Value ==1 then
2    script.Parent.Base.PointLight2.Range = 18
3    script.Parent.Humanoid.WalkSpeed = 30
4end
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You place the "and" between 2 arguments in an if statement if you want the code inside the statement to execute if BOTH arguments return true.

Let's say for example:

01a = 2
02b = 3
03 
04if a == 2 and b == 3 then
05    *code* --executes because both arguments are true
06end
07 
08if a == 1 and b == 3 then
09    *code* --doesn't execute because 1 argument isn't true (even if 1 is)
10end

If you're familiar with C++, this would translate to "&&"

If you would want the if statement to execute even if 1 argument isn't true you can use "or":

01a = 2
02b = 3
03 
04if a == 2 or b == 3 then
05    *code* --executes because both arguments are true
06end
07 
08if a == 1 or b == 3 then
09    *code* --executes because 1 argument is true (even if 1 isn't)
10end
1if a == 0 and b == 1 then
2    *code* --doesn't execute because neither argument is true
3end
0
You would need a double == for an if statement btw. climethestair 1663 — 6y

Answer this question