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 5 years ago
Edited 5 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?

local balance = {-1, 1}
local v = game.Lighting:WaitForChild("ONE")
local sway = math.random(1, 100) * .01
local y = math.random(1, 6)
local x = math.random(1, 8)
while wait() do

wait(15)
v.Value = v.Value + sway
for y = 1,2 do v.Value = v.Value * 1.1 * math.random(1, 1.5)
for x = 2,3 do v.Value = v.Value - v.Value + 2.50
end
end
end

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

1 answer

Log in to vote
0
Answered by 5 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:

local i = 1

if i == 1 then 
    print('YO!')
else
    print('i is not 1')
end

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:

local balance = {-1, 1}
local v = game.Lighting:WaitForChild("ONE")
local sway = math.random(1, 100) * .01
local y = math.random(1, 6)
local x = math.random(1, 8)

while true do
    wait(15)
    v.Value = v.Value + sway
    if y == 1 then
        -- do what you want
    elseif y == 2 then
        -- do what you want
    elseif y == 3 then
        -- do what you want
    elseif y == 4 or y == 5 then -- you can also do this
        -- do what you want
    end
end

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 — 5y
0
what if i want it to change a value, it doesn't seem to work like this JohnerDev 27 — 5y
0
NVM JohnerDev 27 — 5y
0
lol i forgot about elseif JohnerDev 27 — 5y
Ad

Answer this question