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 make it that the script stops at a certain place? (ANSWERED)

Hello everyone, I'm trying to make it so that my script doesn't run all at once and wait() is not what I want. When I click, all of the script starts, is there any way to stop it once the variable toggle has changed?

local button = script.Parent

local function click()
	local toggle = 1
	if toggle == 1 then
		button.Font = Enum.Font.Arcade
		toggle = 2
	end
	if toggle == 2 then
		button.Font = Enum.Font.Highway
		toggle = 3
	end
	if toggle == 3 then
		button.Font = Enum.Font.Fantasy
		toggle = 4
	end
	if toggle == 4 then
		button.Font = Enum.Font.GothamBold
		toggle = 5
	end
	if toggle == 5 then
		button.Font = Enum.Font.SourceSans
		toggle = 1
	end
end

button.MouseButton1Down:Connect(click)

Thanks, any help would be appreciated

2 answers

✓ Accepted answer

I know you said that you didn´t want any wait(). However, I am not sure that you have considered this. You could use a repeat until loop combined with wait() to stop your script from running until a certain condition is met.

local button = script.Parent
	 
local function click()
	local toggle = 1
		
	repeat wait()
		if toggle == 1 then
	       	 	button.Font = Enum.Font.Arcade
	       		toggle = 2
		end
	 	
		if toggle == 2 then
	     		button.Font = Enum.Font.Highway
			toggle = 3
		end

		if toggle == 3 then
	    		button.Font = Enum.Font.Fantasy
	   		toggle = 4
		end
	
		if toggle == 4 then
	        	button.Font = Enum.Font.GothamBold
	       		toggle = 5
		end
	
		if toggle == 5 then
		        button.Font = Enum.Font.SourceSans
			toggle = 1
		end
	until --statement is met
end
	 
button.MouseButton1Down:Connect(click)

2 comments

0

Please remember to accept my answer if you find it useful.

0

Wait guys, sorry, I'm just stupid, I could've just used elseif, sorry.

I could've just used elseif instead of multiple if statements.

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