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

How can I stop a while true loop if something = false?

Hello, I am making a slideshow for my hotel for trainings. I want it so the welcome screen changes from 2 different messages and fades... I got that to work. The issue is, if I want to go to the next page(So we can start the slideshow), it continues the loop from the welcome screen. I do not want that. If the page is 1, I want the loop to stop. Here is my code: NOTE I DO NOT LIKE USING VARIABLES!!! And the code cut off, hit the button when mouse is over the code to see the "full" code.

loop = false




function onClicked(playerWhoClicked)
											--On Welcome--
	
										if script.Parent.Page.Value == 0 then --If Only welcome page = false(Meaning not on welcome page) then do...--
													print(2)
													script.Parent.Display.Decal.Texture = "rbxassetid://109582196"
													print(3)
													script.Parent.Display.SurfaceGui.TextLabel.Text = "Welcome to training! This is the Reception Training. Please STS."					
													wait(5)
													loop = true
													
													
													--END OF CHANGING--	
														
													
														if loop == true then
															
														--START OF TEXT CHANGING--
														
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .1
														
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .2
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .3
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .4
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .5
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .6
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .7
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .8
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .9
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = 1
														wait(.15)
														
													--END OF TEXT FADING--
													
													--START OF NEW WELCOME TEXT--
													
														script.Parent.Display.SurfaceGui.TextLabel.Text = "Please enjoy a cup of coffee and talk a while! We will begin soon."
														
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .9
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .8
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .7
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .6
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .5
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .4
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .3
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .2
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .1
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = 0
														wait(5)
														
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .1
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .2
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .3
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .4
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .6
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .7
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .8
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .9
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = 1
													
														
														--END OF NEW TEXT--
														
														
														--START OF FADING--
														
														script.Parent.Display.SurfaceGui.TextLabel.Text = "Welcome to training! This is the Reception Training. Please STS."		
														
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .9
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .8
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .7
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .6
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .5
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .4
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .3
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .2
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = .1
														wait(.15)
														script.Parent.Display.SurfaceGui.TextLabel.TextTransparency = 0
														wait(5)
														
														end --END OF LOOP--
													
													
													
													
						
										end --End of the IF Statement--
										
										
										
											
										if script.Parent.Page.Value == 1 then
											
												script.Parent.Display.SurfaceGui.TextLabel.Text = "Please copy the following in your notes:"
												
												wait(5)
												script.Parent.Display.SurfaceGui.TextLabel.Text = "Reception - Gives rooms out to customers. Can ONLY use :give."
										end

end --End Of the Function--




	
	
	
	
	
	








































--When to call the function--

script.Parent.Part.SurfaceGui.NextButton.MouseButton1Down:connect(onClicked)
script.Parent.Part.SurfaceGui.PrevButton.MouseButton1Down:connect(onClicked)
script.Parent.Part.SurfaceGui.WelcomeButton.MouseButton1Down:connect(onClicked)

2 comments

2

this code gave me aids

0

im going to go to the hospital, thanks alot.

1 answer

✓ Accepted answer

I don't see your while true loop but if you want a while true loop to stop when your variable "loop = false" just include a break in your loop when the variable is false. Also, you've said you don't like variables but using a variable for your numbers or maybe a for loop will definitely help you instead of pasting the lines over and over again.

while true do
--Stuff
if loop == false then
break
end
wait()
end

3 comments

0

Ok, but what if the value "loop" changes during the process of the slideshow? Like if it is changing text for the welcome page, and during it I hit next page, I will have to wait until the 1 round of the loop finishes. How would I fix that?

0

Ok, I think I got it. I would have to put the if loop == false then break end below every line right?

0

A loop runs the lines you place in it over and over again meaning it will run the "if loop == false then break end" each time it goes through your lines and break the loop if the variable changes.

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