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

How do i make y if it's a certain number do what i say and not if it isn't?

Asked by 6 years ago
Edited 6 years ago

How do I make y if it is a certain number do what I say and not do what I say if it doesn't choose that number like for example if math.random 1 got chosen then it would do v.Value = v.Value * 1.1 * math.random(1, 1.5) but if it's any other number like 5 it wouldn't do that. Or is this not possible?

01local balance = {-1, 1}
02local v = game.Lighting:WaitForChild("ONE")
03local sway = math.random(1, 100) * .01
04local y = math.random(1, 6)
05local x = math.random(1, 8)
06while wait() do
07 
08wait(15)
09v.Value = v.Value + sway
10for y = 1,2 do v.Value = v.Value * 1.1 * math.random(1, 1.5)
11for x = 2,3 do v.Value = v.Value - v.Value + 2.50
12end
13end
14end
0
so like if the math gets 2 it will do something but if it gets 1 or 3-6 it won't do that thing, idk if this helps maybe even confuses u more but idk how to explain it very well JohnerDev 27 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

What you are looking for is a If statement.

If statements run only when the statements is true or false depending on how you use not.

To put it as an example:

1local i = 1
2 
3if i == 1 then
4    print('YO!')
5else
6    print('i is not 1')
7end

In this example, if i is 1 (which it is) it will print YO, while if i is not 1 (anything other then 1) it will print something else.

From you script it seems like you are trying to make a loop (make it continues) here is your code refined:

01local balance = {-1, 1}
02local v = game.Lighting:WaitForChild("ONE")
03local sway = math.random(1, 100) * .01
04local y = math.random(1, 6)
05local x = math.random(1, 8)
06 
07while true do
08    wait(15)
09    v.Value = v.Value + sway
10    if y == 1 then
11        -- do what you want
12    elseif y == 2 then
13        -- do what you want
14    elseif y == 3 then
15        -- do what you want
16    elseif y == 4 or y == 5 then -- you can also do this
17        -- do what you want
18    end
19end

A few things, you have to add what you want to do and I want to make sure that you know x, y and sway will always stay the same because it only runs once.

If you want it to keep changing, place the variables inside the while true do loop so it runs again.

Hopefully this helped you.

Best of luck!

0
local balance = {-1, 1} local v = game.Lighting:WaitForChild("ONE") math.randomseed(tick()) local sway = math.random(1, 100) * math.random(0.05, 0.15) local y = math.random(1,50) local x = math.random(1,40) while wait() do wait(15) v.Value = v.Value + sway if y == 10 then v.Value = v.Value * 1.1 * math.random(1, 2.1) if x == 5 then v.Value = v.Value - v.Value + 2.50 end end end JohnerDev 27 — 6y
0
what if i want it to change a value, it doesn't seem to work like this JohnerDev 27 — 6y
0
NVM JohnerDev 27 — 6y
0
lol i forgot about elseif JohnerDev 27 — 6y
Ad

Answer this question