Error: Line 109, "no loop to break"

Award = 10
Award2 = 5
local gui = game.Workspace.Part1.v.z

game.Players.PlayerAdded:connect(function(plr)
	local leaderstats = Instance.new("IntValue")
	leaderstats.Name = "leaderstats"
	
	local points = Instance.new("IntValue")
	points.Name = "Points"
	
	points.Parent = leaderstats
	leaderstats.Parent = plr
end)

function Fight()
	for _, player in pairs(game.Players:GetPlayers()) do
		if player and player.Character then
			local humanoid = player.Character:WaitForChild("Humanoid")
			humanoid.MaxHealth = 10000
			humanoid.Health = 10000
		end
	end
	for i = 15, 0, -1 do
		if i <= 9 then
			gui.Text = "Intermission (0:0"..i..")"
		else
			gui.Text = "Intermission (0:"..i..")"
		end
		wait(1)
	end
	gui.Text = "Now choosing duelers."
	wait(5)
	
	local plrs = game.Players:GetPlayers()
	local p1 = plrs [math.random(1, #plrs)]
	local p2 = plrs [math.random(1, #plrs)]
	ended = false
	repeat p2 = plrs[math.random(1, #plrs)] until p2 ~= p1
	
	gui.Text = p1.Name.. " and " ..p2.Name.. " have been chosen to duel."
	wait(3)
	
	p1.Character.Torso.CFrame = CFrame.new(147.5, 14.6, 15) 
	p2.Character.Torso.CFrame = CFrame.new(147.5, 14.6, -59)
	
	local sword1 = game.ServerStorage.Sword1:Clone()
	sword1.Parent = p1.Backpack
	
	local sword2 = game.ServerStorage.Sword2:Clone()
	sword2.Parent = p2.Backpack
	
	for i = 3, 0, -1 do
		gui.Text = "Starting in " ..i
		p1.Character.Humanoid.WalkSpeed = 0
		
		p2.Character.Humanoid.WalkSpeed = 0
		wait(1)
	end

	p1.Character.Humanoid.MaxHealth = 100
	p1.Character.Humanoid.Health = 100
	p1.Character.Humanoid.WalkSpeed = 16
	
	p2.Character.Humanoid.MaxHealth = 100
	p2.Character.Humanoid.Health = 100
	p2.Character.Humanoid.WalkSpeed = 16
	
	for i = 30, 0, -1 do
		gui.Text = "Round, please wait (0:"..i..")"
		if i <= 9 then
			gui.Text = "Round, please wait (0:0"..i..")"
		end
		wait(1)
		p1.Character.Humanoid.Died:connect(function()
			p2.leaderstats.Points.Value = p2.leaderstats.Points.Value + Award
			gui.Text = p2.Name.." has won."
			game:GetService("PointsService"):AwardPoints(p2.userId,150)
			wait(3)
			ended = true
		end)
		if ended == true then
			break
		end
		p2.Character.Humanoid.Died:connect(function()
			p1.leaderstats.Points.Value = p1.leaderstats.Points.Value + Award
			gui.Text = p1.Name.." has won."
			game:GetService("PointsService"):AwardPoints(p1.userId,150)
			wait(3)
			ended = true
		end)
		if ended == true then
			break
		end
		left = false
		connection = game.Players.PlayerRemoving:connect(function(player)
    	if player == p1 then
       		gui.Text = p2.Name.. " has won by default."
       	 	connection:disconnect()
			left = true
			if left == true then
				break
			end
		elseif player == p2 then
       		gui.Text = p1.Name.. " has won by default."
        	connection:disconnect()
			left = true
			if left == true then
				break
			end
   		end
	end
	p1.Character.Torso.CFrame = CFrame.new(190.2, 3.8, -25.6) 
	p1.Character.Humanoid:UnequipTools()
	p1.Backpack:ClearAllChildren()
	
	p2.Character.Torso.CFrame = CFrame.new(184.2, 3.8, -25.6)
	p2.Character.Humanoid:UnequipTools()
	p2.Backpack:ClearAllChildren()
end

while true do
	if game.Players.NumPlayers > 1 then
		wait(1)
		Fight()
	elseif game.Players.NumPlayers == 1 then
		gui.Text = "Waiting for 2 or more players."
	end
	wait()
end

3 comments

0

What you could try is set a value "endEarly" to false and then you set it to true when you put break and at the end of the loop it checks if it is true and if so it breaks. I have no idea if this will help but it's worth a shot

0

Could you maybe answer that in what you said?...

0

Instead of "break" make it "return end". That might work.