[SOLVED] "break" not working after adding this function

I got a freemodel script of a system that changes the AmbientReverb when you go into a specific location. You cannot leave this location, so I decided to end your suffering if you get stuck in there by making a 5% chance you get teleported to the backrooms, because why not?

Anyway, when I call the function to teleport the player to the backrooms, the break, which is after the function, just becomes completely ignored by the script, even though I’m using a delay function that will have the function be called after the break…

Here’s the code: (LocalScript in StarterPlayer.StarterCharacterScripts)

-- Put this LocalScript in StarterCharacterSCripts in StarterPlayer 

local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local SoundService = game:GetService("SoundService")
local ChanceToBackrooms = math.random(1, 100)

local localPlayer = Players.LocalPlayer

local reverbTags = {
	-- add more reverbs here, by looking from the 2 examples below (DON'T FORGET THE COMMAS)
	["Hangar"] = Enum.ReverbType.Hangar
}

function TeleToBackrooms()
	if ChanceToBackrooms > 95 then
		localPlayer.CharacterAdded:Wait():SetPrimaryPartCFrame(workspace.TeleDestination.CFrame)
		game.Lighting.FogEnd = 500
		game.Lighting.FogColor = Color3.fromRGB(10, 10, 10)
		print("Character Successfully Teleported!")
	end
end

for i, v in pairs(game.Workspace.Regions.Reverb:GetChildren()) do
	for i1, v1 in pairs(v:GetChildren()) do
		CollectionService:AddTag(v1, v.Name)
	end
end

local parts = {}

for i, v in pairs(reverbTags) do
	for _, v1 in pairs(CollectionService:GetTagged(i)) do
		parts[v1] = v
	end
end

local function positionInPart(part, position)
	local extents = part.Size / 2
	
	local extentsx = part.Size.x / 2
	local extentsy = part.Size.y / 2
	local extentsz = part.Size.z / 2
	
	if extentsx > 0 then
		extentsx = math.abs(extentsx) * -1
	end
	if extentsy > 0 then
		extentsy = math.abs(extentsy) * -1
	end
	if extentsz > 0 then
		extentsz = math.abs(extentsz) * -1
	end
	
	local extents2 = Vector3.new(extentsx, extentsy, extentsz)
	local offset = part.CFrame:pointToObjectSpace(position)
	return offset.x < extents.x and offset.x > extents2.x
		and offset.y < extents.y and offset.y > extents2.y
		and offset.z < extents.z and offset.z > extents2.z
end

local reverbType = SoundService.AmbientReverb

while true do 
	wait()
	if not localPlayer then
		return
	end

	local character = localPlayer.Character
	local newReverbType = Enum.ReverbType.Hallway -- change the "NoReverb" to a different if want the base reverb to be different

	if character and character.PrimaryPart then
		local position = character.PrimaryPart.Position
		
		for i, v in pairs(parts) do
			if positionInPart(i, position) then
				newReverbType = v
				task.delay(math.random(25, 60), TeleToBackrooms)
				print(ChanceToBackrooms)
				break
			end
		end
	end

	if newReverbType ~= reverbType then
		SoundService.AmbientReverb = newReverbType
		reverbType = newReverbType
	end
end


Also, yes, I will accept “just make it 100%” as an answer, BUT… Anything that isn’t naturally in the if statement is going to cause it to have issues, mainly the reverb just entirely not changing.

It will only break the for loop that it is inside, not the while loop. Is that what you mean?

No, it is supposed to break the for loop. If I remove that entire teleportation function, everything works normal. The loop breaks and doesn’t run when it doesn’t need to.

Also, when testing the teleportation by making the chances all 100%, I figured out it is specifically the if statement causing this.

I came up with a fix, where I simply created a part, that when touched, would change the reverb and also give the chance of teleportation to the backrooms. This is also better because, since the old one also checked when the player left said area, the reverb would revert back. This doesn’t revert it back, as you can’t leave this area anyway