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

How do I keep this if statement looping and not looping?

Asked by 5 years ago

I need to know how to keep this if statement from looping until a condition is met where it stops looping

But I have tried repeat ... until and while script.Parent.Value >= 40 do and they do not work.

repeat
    wait(1) -- this is to prevent game script time out from occuring
    script.Parent.Parent.tornadowinds.intensify.Disabled = false
    script.Parent.Parent.tornado.ParticleEmitter.Enabled = true
    script.Parent.Parent.tornado.suckcloud.ParticleEmitter.Enabled = true
    script.Parent.Parent.tornadowinds.Value = 65
    script.Parent.Parent.cloudmain.Stats.Frame.StormName.Text = "Tornado 1"
    script.Parent.Parent.tornadowinds.control.Disabled = false
until script.Parent.Value >= 40
0
the while loop should work. what you have in the script and your explanation are contradictory though, do you want it running before 40 or after 40? DinozCreates 1070 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

integrate the condition into the while loop. you could also watch the value for changes and check only then, that would probably be more efficient instead of running this every second until condition is met.

script.Parent.Changed:Connect(function()
    if script.Parent.Value >= 40 then
        script.Parent.Parent.tornadowinds.intensify.Disabled = false
        script.Parent.Parent.tornado.ParticleEmitter.Enabled = true
        script.Parent.Parent.tornado.suckcloud.ParticleEmitter.Enabled = true                       script.Parent.Parent.tornadowinds.Value = 65
        script.Parent.Parent.cloudmain.Stats.Frame.StormName.Text = "Tornado 1"
        script.Parent.Parent.tornadowinds.control.Disabled = false
    end
end)
0
The <= 39 should be >= 40 LoganboyInCO 150 — 5y
0
your script is running until value is 39, so i just did the same. DinozCreates 1070 — 5y
0
Also the script runs after 1 second (when the script loads 1 second later the code line 3-8 is ran) LoganboyInCO 150 — 5y
0
isnt that what you wanted? you werent very clear DinozCreates 1070 — 5y
View all comments (5 more)
0
no, whenever the script is loaded one second later it runs everything, its supposed to keep looping the if statement has not met its condition, once its condition is met it stops looping the if statement and removes this script LoganboyInCO 150 — 5y
0
maybe im confused or maybe you are, but this should run until the value is 40. then it shouldnt unless the value becomes less than 40 again. if you want it to permanently disable after condition is met we can do that too. DinozCreates 1070 — 5y
0
ill show a gif of it then. https://gyazo.com/820c6bf85e7c69da6045e97f19e3c2f8 LoganboyInCO 150 — 5y
0
hmm, try this. DinozCreates 1070 — 5y
0
Works well, ty LoganboyInCO 150 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
while wait(1) do
    if script.Parent.Value >= 40 then
        break
    else
        script.Parent.Parent.tornadowinds.intensify.Disabled = false
         script.Parent.Parent.tornado.ParticleEmitter.Enabled = true
         script.Parent.Parent.tornado.suckcloud.ParticleEmitter.Enabled = true                               
                 script.Parent.Parent.tornadowinds.Value = 65
         script.Parent.Parent.cloudmain.Stats.Frame.StormName.Text = "Tornado 1"
            script.Parent.Parent.tornadowinds.control.Disabled = false
    end
end
0
There must be an explanation. rochel89 42 — 5y
0
The script below "else" runs after 1 second, also while wait() do is deprecated ;pppp, so tl;dr code below else runs after one second LoganboyInCO 150 — 5y
0
this is also a super inefficient way to do this DinozCreates 1070 — 5y
0
xd TheluaBanana 946 — 5y

Answer this question