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 5 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


local Player = game:GetService("Players").LocalPlayer local stats = Player:WaitForChild("leaderstats") local Light = Player.leaderstats.Light while true do if script.Parent.V.Value == 1 and if Light.Value ==1 then script.Parent.Base.PointLight2.Range = 18 script.Parent.Humanoid.WalkSpeed = 30 end end
2
if script.Parent.V.Value == 1 and Light.Value == 1 then Rare_tendo 3000 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago

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

if condition and condition2 then
    ...
end

In your case...

if script.Parent.V.Value == 1 and Light.Value ==1 then
    script.Parent.Base.PointLight2.Range = 18
    script.Parent.Humanoid.WalkSpeed = 30
end
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 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:

a = 2
b = 3

if a == 2 and b == 3 then
    *code* --executes because both arguments are true
end

if a == 1 and b == 3 then
    *code* --doesn't execute because 1 argument isn't true (even if 1 is)
end

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":

a = 2
b = 3

if a == 2 or b == 3 then
    *code* --executes because both arguments are true
end

if a == 1 or b == 3 then
    *code* --executes because 1 argument is true (even if 1 isn't)
end
if a == 0 and b == 1 then
    *code* --doesn't execute because neither argument is true
end
0
You would need a double == for an if statement btw. climethestair 1663 — 5y

Answer this question