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

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

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

1 comment

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?

2 answers

✓ Accepted answer

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)

9 comments

0

The <= 39 should be >= 40

0

your script is running until value is 39, so i just did the same.

0

Also the script runs after 1 second (when the script loads 1 second later the code line 3-8 is ran)

0

isnt that what you wanted? you werent very clear

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

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.

0
0

hmm, try this.

0

Works well, ty

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

4 comments

0

There must be an explanation.

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

0

this is also a super inefficient way to do this

0

xd

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