Skip rest of code when 'if then' statement is met

i have a custom chat gui script for a phone
this is the code that controls what displays in the message boxes

	Tool.Words.Changed:connect(function()
		if (Tool.Words.Value == "*Dial Tone*") then
			print("DialTonetext RECOGNIZED")
			return
		elseif (Tool.Words.Value ~= "") then
			lastphrase = Tool.Words.Value
			if lastphrase == "*Dial Tone*" then
				msgs.MSG1.Text = "*Dial Tone*"
				return else
			local filtered
			local success, errorMsg = pcall(function()
				filtered = chat:FilterStringAsync(lastphrase, player, player)
			end)
			if filtered and success then
			if (msgs:findFirstChild("MSG5") ~= nil) then
				for i = 5, 2, -1 do
					local num1 = i
					local num2 = i - 1
						msgs:findFirstChild("MSG" ..num1).Text = msgs:findFirstChild("MSG" ..num2).Text
						end
				msgs.MSG1.Text = filtered
				else
				msgs.MSG1.Text = errorMsg
				end
			end
		wait(0.1)
				Tool.Words.Value = ""
			end
		end
	end)
	end

the code pretty much changes a StringValue to the player’s most recent chat which will then be displayed in the GUI
anyways
i want to make it if the text “Dial Tone” is the most recent chat it will skip the rest of the code. is this possible?

Try using break maybe?

I’m not super positive, usually return does the job. But if return is not working, definitely try to give break a shot.

ive tried using break already, problem being is that it says “break statement must be inside a loop”

if someCondition then
  return -- skip the rest of the code
end

-- code below this line will not be executed if the 'if' condition is met

Try and have the if statement that returns on the outside, separated from the other if statements

1 Like

i realized that i didnt add an ‘end’ after “return”
“Dial Tone” still doesnt show up, but besides that, it’s skipping over the rest of the code as it should now.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.