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

How can I fix while true do loop (stops working)?

I have this script that works perfect but it isn't looping. It's supposed to loop from line 2, instead, it starts at 12? I know it works to line 149, can anyone help?

local mini = 2
while true do
	for i = 15,1,-1 do
		game.Workspace.Settings.Message.Value = "A new round will start in "..i.." seconds" -- Count down
		wait(1)
	end
	wait(0.01)
	if game.Players.NumPlayers < mini then  -- If it is 1 player then
		game.Workspace.Settings.Message.Value = mini - game.Players.NumPlayers.. " more player need to join." -- Say that we need 1 more player
		wait(5)
	else
		for i,v in pairs(game.Players:GetChildren()) do -- Get all players
			-- Clone Map
			v.PlayerGui.MainGui.RunnerLoader.Visible = true
			v.Character.Torso.CFrame = CFrame.new(184, 3, -90) -- Teleport the players to the map
			v.TeamColor = game.Teams.Runner.TeamColor
			v.PlayerGui.MainGui.Values.Died.Value = false	
			local Players = game:GetService'Players'
			local Playing = Players:GetPlayers()	
			local Murder = Playing[math.random(#Playing)]
			Murder.TeamColor = game.Teams.Catcher.TeamColor
			Murder.Character.Torso.CFrame = CFrame.new(274, 3, -255)
			wait(2)
			game.Workspace.Settings.Message.Value = Murder.Name.." is the catcher, run NOW!"	
			v.PlayerGui.MainGui.RunnerLoader.Visible = false
			Murder.PlayerGui.MainGui.MurderLoader.Visible = true
			Murder.Character.Torso.NameTag.TextLabel.TextColor3 = Color3.fromRGB(255,0,0)
			wait(5)
			game.Workspace.Settings.Message.Value = "The catcher will start to hunt you in 5 seconds"
			wait(1)
			game.Workspace.Settings.Message.Value = "The catcher will start to hunt you in 4 seconds"
			wait(1)
			game.Workspace.Settings.Message.Value = "The catcher will start to hunt you in 3 seconds"
			wait(1)
			game.Workspace.Settings.Message.Value = "The catcher will start to hunt you in 2 seconds"
			wait(1)
			game.Workspace.Settings.Message.Value = "The catcher will start to hunt you in 1 second"
			Murder.PlayerGui.MainGui.MurderLoader.Visible = false
			game.Workspace.Settings.Message.Value = "The current game has 50 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 49 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 48 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 47 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 46 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 45 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 44 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 43 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 42 seconds remaining"
			wait(1)			
			game.Workspace.Settings.Message.Value = "The current game has 41 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 40 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 39 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 38 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 37 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 36 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 35 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 34 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 33 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 32 seconds remaining"
			wait(1)			
			game.Workspace.Settings.Message.Value = "The current game has 31 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 30 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 29 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 28 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 27 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 26 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 25 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 24 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 23 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 22 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 21 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 20 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 19 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 18 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 17 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 16 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 15 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 14 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 13 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 12 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 11 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 10 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 9 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 8 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 7 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 6 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 5 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 4 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 3 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 2 seconds remaining"
			wait(1)
			game.Workspace.Settings.Message.Value = "The current game has 1 second remaining"
			wait(1)
			local text
			local PlayersSurvived = {}
			if v.PlayerGui.MainGui.Values.Died.Value == false then
				table.insert(PlayersSurvived, v.Name)
			end
			v.PlayerGui.MainGui.Values.Died.Value = true
			v.Character.Torso.CFrame = CFrame.new(4, 104, -5)
			v.TeamColor = game.Teams.Spectator.TeamColor
			Murder.Character.Torso.NameTag.TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
			text = table.concat(PlayersSurvived, ", ") .. " did survive!"
			game.Workspace.Settings.Message.Value = text
			wait(5)
		end
	end
end

2 comments

0

You used the for loop at the start, but at the end you just copy paste ;(

0

Good lord....

1 answer

✓ Accepted answer

If you look carefully, it does not start at line 12, but the first time normally executes the beginning.

After reaching line 150, it loops back to the beginning of the for loop you defined at line 12, and does the countdown for the next player. All exactly as you specified!

I suggest you put an end statement at line 18 and remove one at the end.

Then fix the indentation and please, like theCJarmy7 suggests, use a loop for your countdown like you did at the beginning of your script. :)

Hope this helps!

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