Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] Why does this script's While True do stop working?

The while true do stops working after a player wins a duel and because of that it doesn't start a new match. Sometimes it also doesn't even start a match and stops printing.

local isMatchGoing = false

local players = game:GetService("Players")

	while true do
			wait(1)
			print(isMatchGoing)
		if not isMatchGoing and #players:GetPlayers() > 1 then
		local random1 = math.random(1,#players:GetPlayers())
		local random2 = math.random(1,#players:GetPlayers())
		if random1 == random2 then return end
		
			local plr1 = players:GetPlayers()[random1]
			local plr2 = players:GetPlayers()[random2]
			
			if plr1 and plr2 then
				isMatchGoing = true
				local chr1 = plr1.Character or plr1.CharacterAdded:Wait()
				local chr2 = plr2.Character or plr2.CharacterAdded:Wait()
				
				chr1.HumanoidRootPart.CFrame = workspace.start1.CFrame
				chr2.HumanoidRootPart.CFrame = workspace.start2.CFrame
				
				local died
				
				died = chr1.Humanoid.Died:Connect(function()
					if isMatchGoing then
						plr2.leaderstats.Wins.Value = plr2.leaderstats.Wins.Value + 1
						plr2:LoadCharacter()
					end
					isMatchGoing = false
					died:Disconnect()
				end)
				
				local died2
				
				died2 = chr2.Humanoid.Died:Connect(function()
					if isMatchGoing then
						plr1.leaderstats.Wins.Value = plr1.leaderstats.Wins.Value + 1
						plr1:LoadCharacter()
					end
					isMatchGoing = false
					died2:Disconnect()
				end)
			end
		end
	end

1 comment

0

Try disconnecting both died and died2 in each connections above, see if it works!

1 answer

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