Break not working?

I have this script inside of a “while wait(3) do” loop. Read it and please tell me why it isn’t working.

		for _, v in pairs(game.Workspace:GetPartsInPart(doorFunction1)) do --All the parts next to the door
			if v.Parent == script.Parent or counter > 0 then --If the part is the local character, or if the counter has been started
				contains = 1 --Ignore this
				if game.Workspace.Map.RightDoor.ClickPart.Closed.Value == true then --If the door is closed
					counter = counter + 1 --Increase the counter (also starts the counter)
					if counter > 10 then 
						script.Parent.HumanoidRootPart.CFrame = game.Workspace.Map.Teleporters.FreddyTP.CFrame --Reset character
						knock:FireServer("Right") --Fire the server
						counter = 0 --Reset counter
					end
				else --If the local character is not by the door, and the counter has not been started
					counter = 0 --Reset the counter
				end
				break --Break if the part is the local character or if the counter is over 0. When this happens, I just want it to exit the for loop and continue on
			end
            --for some reason after the break, it repeats the for loop twice and then carries on
		end

Here is the script again, but with stuff removed that you might not need to see, and removed the comments.

		for _, v in pairs(game.Workspace:GetPartsInPart(doorFunction1)) do
			if v.Parent == script.Parent or counter > 0 then
				if game.Workspace.Map.RightDoor.ClickPart.Closed.Value == true then
					counter = counter + 1
					if counter > 10 then
						counter = 0
					end
				else
					counter = 0
				end
				break
			end
		end

Try putting “break” under the first end not the second

Which end are you talking about? Can you mark it for me?
Also I edited the script so you have more context.

The one at the very bottom
Put the break in between the – notes

That won’t work, because that means the for loop just won’t work right. I want it to keep looping through until it finds the character, and if it does then it will break. Breaking should ignore and “if” statement, but for some reason it looks like it doesn’t.

I give up on solving scripts that. good luck trying to find the solution, there’s definitely better scripters out there than me.

1 Like

I got rid of the “counter > 0”

if v.Parent == script.Parent or counter > 0 then
if v.Parent == script.Parent then

and I added this after the for loop:

		if counter > 0 and contains == 0 then
			if game.Workspace.Map.RightDoor.ClickPart.Closed.Value == true then
				counter = counter + 1
				if counter > 10 then
					script.Parent.HumanoidRootPart.CFrame = game.Workspace.Map.Teleporters.FreddyTP.CFrame
					knock:FireServer("Right")
					counter = 0
				end
			else
				counter = 0
			end
		end

I’m questioning how it works now, but just as long as it’s functional it’s fine with me