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

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

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 

1 comment

2

if script.Parent.V.Value == 1 and Light.Value == 1 then

2 answers

✓ Accepted answer

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

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

1 comment

0

You would need a double == for an if statement btw.

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