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

My script stopped looping and I've been stuck trying to fix it?

While I was scripting my script stopped looping and I've been stuck trying to fix it.

wait(3.4)
local Elimineted = require(script.Eliminated)
local number
local Round1 = workspace.Ost.Round1
local Round2 = workspace.Ost.Round2
local Round3 = workspace.Ost.Round3
local Load = workspace.Ost.Selecting

script.SubtractNumbers.Disabled = true

while wait(.1) do
	local players = game.Players:GetPlayers()
	if #players > 1 then
		
		print("Round Match Started")
		
		wait(.1)

		game.ReplicatedStorage.PlrsInGame.Value = 0
		
		local roundOneMaps = game.ServerStorage.RoundOne:GetChildren()
		number = math.random(1,#roundOneMaps)
		local clonedMap = roundOneMaps[number]:Clone()
		clonedMap.Name = "Map"
		clonedMap.Parent = workspace

		game.ReplicatedStorage.ChangeText:FireAllClients("Qualified")

		game.ReplicatedStorage.Qualified.Value = 0
		wait(8)
		
		Load.Playing = true
		wait(7.4)

		players = game.Players:GetPlayers()

		if #players <= 4 then
			game.ReplicatedStorage.Limit.Value = #players - 0
		else
			game.ReplicatedStorage.Limit.Value = #players - 1
						
		end
		for i,v in pairs(players)do
			if v.Character:FindFirstChild("HumanoidRootPart")then
				v.Character.HumanoidRootPart.Position = clonedMap.SpawnPart.Position 
				local tag= Instance.new("BoolValue")
				tag.Name = "InGame"
				tag.Parent = v
			end
		end
		
		wait(1)
		
		Load.Playing = false
		
		print("Round 1 Started")
		
		wait(3.7)
		
		Round1.Playing = true
		Round1.Looped = true
		
		script.SubtractNumbers.Disabled = false
		local Time = game.ReplicatedStorage.Timer.Value
		game.ReplicatedStorage.Timer.Value = 195
		while Time > 0 do
			game.ReplicatedStorage.TimeEvent:FireAllClients(Time)
			wait(1)
		end
		
		
		while game.ReplicatedStorage.Qualified.Value ~= game.ReplicatedStorage.Limit.Value and  #players ~= 1 do
			players = game.Players:GetPlayers()
			if game.ReplicatedStorage.Qualified.Value == game.ReplicatedStorage.Limit.Value then
				game.ReplicatedStorage.Timer.Value = 0
			end
			if game.ReplicatedStorage.Timer.Value == 0 then
				wait(.1)
				break
			elseif #players == 0 then

				wait(1)
				break
			else
				wait(.1)
			end     
		end

		print("Round 1 Over")
		
		Round1.Playing = false
		game.Lighting.ClockTime = 12
		Round1.TimePosition = 0
		script.SubtractNumbers.Disabled = true

		players = game.Players:GetPlayers()

		for i,v in pairs(players) do
			if v.Character:FindFirstChild("HumanoidRootPart")then
				v.Character.HumanoidRootPart.CFrame = CFrame.new(-212.673, 9.792, 1640.907)                                          
			end
		end

		game.Workspace.Map:Destroy()

		for i,v in pairs(players)  do
			if not v:FindFirstChild("Qualified") then
				if v:FindFirstChild("InGame") then
					local elimTag = Instance.new("BoolValue")
					elimTag.Parent = v
					elimTag.Name = "elimTag"
				end	
			end
		end

		wait(5)
		Elimineted.Qualified()

		players = game.Players:GetPlayers() 

		wait(5)
		for i,v in pairs(players) do
			if v.Character:FindFirstChild("HumanoidRootPart")then
				v.Character.HumanoidRootPart.CFrame = CFrame.new(-212.673, 9.792, 1640.907)                                          
			end
		end
		
		wait(5)
		
		--Round 2

		players = game.Players:GetPlayers()

		local roundtwoMaps = game.ServerStorage.RoundTwo:GetChildren()
		number = math.random(1,#roundtwoMaps)
		local clonedMap = roundtwoMaps[number]:Clone()
		clonedMap.Name = "Map"
		clonedMap.Parent = workspace

		game.ReplicatedStorage.ChangeText:FireAllClients("Qualified")
		game.ReplicatedStorage.Qualified.Value = 0

		wait(8)
		
		Load.Playing = true
		wait(7.4)

		game.ReplicatedStorage.Limit.Value = 2

		for i,v in pairs(players)do
			if v:FindFirstChild("InGame")then
				v.Character.HumanoidRootPart.Position = clonedMap.SpawnPart.Position 
			end
		end
		
		wait(1)
		Load.Playing = false

		print("Round 2 Started")

		wait(3.7)
		
		Round2.Playing = true
		Round2.Looped = true
		
		script.SubtractNumbers.Disabled = false
		local Time = game.ReplicatedStorage.Timer.Value
		game.ReplicatedStorage.Timer.Value = 195
		while Time > 0 do
			game.ReplicatedStorage.TimeEvent:FireAllClients(Time)
			wait(1)


		while game.ReplicatedStorage.Qualified.Value ~= game.ReplicatedStorage.Limit.Value and  #players ~= 1 do
			players = game.Players:GetPlayers()
			if game.ReplicatedStorage.Qualified.Value == game.ReplicatedStorage.Limit.Value then
				game.ReplicatedStorage.Timer.Value = 0
			end
			if game.ReplicatedStorage.Timer.Value == 0 then
				wait(.1)
				break
			elseif #players == 0 then

				wait(1)
				break
			else
				wait(.1)
			end     
		end

		print("Round 2 Over")
		
		Round2.Playing = false
		game.Lighting.ClockTime = 12
			Round2.TimePosition = 0
			script.SubtractNumbers.Disabled = true

		players = game.Players:GetPlayers()

		for i,v in pairs(players) do
			if v.Character:FindFirstChild("HumanoidRootPart")then
				v.Character.HumanoidRootPart.CFrame = CFrame.new(-212.673, 9.792, 1640.907)                                          
			end
		end

		game.Workspace.Map:Destroy()

		for i,v in pairs(players)  do
			if not v:FindFirstChild("Qualified") then
				if v:FindFirstChild("InGame") then
					local elimTag = Instance.new("BoolValue")
					elimTag.Parent = v
					elimTag.Name = "elimTag"
				end	
			end
	end

		wait(5)
		Elimineted.Qualified()

		players = game.Players:GetPlayers() 

		wait(5)
		for i,v in pairs(players) do
			if v.Character:FindFirstChild("HumanoidRootPart")then
				v.Character.HumanoidRootPart.CFrame = CFrame.new(-212.673, 9.792, 1640.907)                                          
			end
	end

		wait(5)

		--round 3
		
		local roundtreeMaps = game.ServerStorage.RoundThree:GetChildren()
		number = math.random(1,#roundtreeMaps)
		local clonedMap = roundtreeMaps[number]:Clone()
		clonedMap.Name = "Map"
		clonedMap.Parent = workspace

		game.ReplicatedStorage.ChangeText:FireAllClients("Eliminated")
		game.ReplicatedStorage.Qualified.Value = 0
		wait(8)
		
		Load.Playing = true
		wait(7.4)
		
		players = game.Players:GetPlayers()

		for i,v in pairs(players)do
				if v.Character:FindFirstChild("HumanoidRootPart")then
				if v:FindFirstChild("InGame") then	
					v.Character.HumanoidRootPart.Position = clonedMap.SpawnPart.Position
					game.ReplicatedStorage.PlrsInGame.Value = game.ReplicatedStorage.PlrsInGame.Value + 1
				end	
			end
			end

		game.ReplicatedStorage.EliminatedInRound.Value = 0

		if game.ReplicatedStorage.PlrsInGame.Value % 2 == 0 then
			--even ammount of players
			game.ReplicatedStorage.ElimLimit.Value = game.ReplicatedStorage.PlrsInGame.Value/2
		else
			--odd ammount of players
			game.ReplicatedStorage.ElimLimit.Value = (game.ReplicatedStorage.PlrsInGame.Value/2) - .5
		end
		
		wait(1)
		Load.Playing = false

		print("Round 3 Started")

		wait(3.7)
		
		Round3.Playing = true
		Round3.Looped = true

		while game.ReplicatedStorage.EliminatedInRound.Value ~= game.ReplicatedStorage.ElimLimit.Value and  #players ~= 1 do
			players = game.Players:GetPlayers()
			if game.ReplicatedStorage.EliminatedInRound.Value == game.ReplicatedStorage.ElimLimit.Value then
				wait(.1)
				break
			elseif #players == 1 then
				local Winner = game.ServerStorage.WinBlock:Clone()
				Winner.Parent = game.Workspace
				break
			else
				wait(1)
			end     
			end
			
		print("Round 3 Over")
		
		wait(.1)
		
		Round3.Playing = false
		game.Lighting.ClockTime = 12
			Round3.TimePosition = 0
			script.SubtractNumbers.Disabled = true

		players = game.Players:GetPlayers()

		for i,v in pairs(players) do
			if v.Character:FindFirstChild("HumanoidRootPart")then
				v.Character.HumanoidRootPart.CFrame = CFrame.new(-212.673, 9.792, 1640.907)                                          
			end
		end

		game.Workspace.Map:Destroy()

		wait(.1)
		
		players = game.Players:GetPlayers()
		for i,v in pairs(players) do
			if v:FindFirstChild("Qualified") then
				v.Character.HumanoidRootPart.CFrame = CFrame.new(4623.37, 14.208, -49.677)
			end
			end

		game.ReplicatedStorage.WinnerCam:FireAllClients()

		wait(11)
		
		print("Winner!")

		for i,v in pairs(players) do
			if v.Character:FindFirstChild("HumanoidRootPart")then
				v.Character.HumanoidRootPart.CFrame = CFrame.new(-212.673, 9.792, 1640.907) 
				
			if v:FindFirstChild("elimTag") then
					v.elimTag:Destroy()
					
					end
				
			if v:FindFirstChild("InGame") then
						v.InGame:Destroy()
						
				end
					
				if v:FindFirstChild("Qualified") then
					v.Qualified:Destroy()
					
					end
					wait(.1)
					
					--Reset All for preventing invis players
					for i, player in ipairs(game.Players:GetPlayers()) do
						if player.Character then
							local hum = player.Character:FindFirstChild('Humanoid')
						if hum then
							
						end
							hum.Health = 0
							print("Round Match Ended")
							wait(5)
							end
						end
					end	
				end
			end
end
end

2 comments

0

First of all you need to get rid of those wait() it can be really bad for your game

0

K then what?

1 answer

This script already been fixed so Ill be inactive for now.

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