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

How do I end a "while true do" statement early?

for example, `` local Plr = game.Players.PlayerAdded:Wait() local InOut = Instance.new("BoolValue") InOut.Name = "InOut" InOut.Value = false InOut.Parent = Plr while true do local mapclone = game.ReplicatedStorage["Hex's"]:Clone() mapclone.Parent = workspace local status = game.ReplicatedStorage.Status local inter = game.ReplicatedStorage.Intermission status.Value = "Time until next round: " inter.Value = 30 repeat inter.Value -= 1 wait(1) until inter.Value == 0 local Josh = game.ReplicatedStorage.Spawn:Clone() Josh.Parent = workspace for i, plr in pairs(game.Players:GetPlayers()) do local Character = plr.Character if Character then Character.HumanoidRootPart.Position = Josh.SpawnPoint.Position plr.Character.Humanoid.WalkSpeed = 0 InOut.Value = true end end

status.Value = ""
inter.Value = 3
wait(1)
inter.Value = 2
wait(1)
inter.Value = 1
wait(1)
inter.Value = ""
status.Value = "Go!"
game.ReplicatedStorage.GameStarted.Value = true
wait(1)
game.ReplicatedStorage.PlayersInRound.Value = #game.Players:GetChildren()
status.Value = ""
inter.Value = ""
Josh:Destroy()
Plr.Character.Humanoid.WalkSpeed = 16
wait(10)
if game.ReplicatedStorage.PlayersInRound.Value == 1 or game.ReplicatedStorage.PlayersInRound.Value == 0 then
	Plr.Character.HumanoidRootPart.Anchored = true
	Plr.PlayerGui.RoundOver.RoundOver:TweenPosition(UDim2.new(-0.4, 0,0.434, 0))
	wait(3)
	Plr.PlayerGui.RoundOver.RoundOver:TweenPosition(UDim2.new(-2.17, 0,0.434, 0))
	Plr.Character.HumanoidRootPart.Anchored = false
	Plr.PlayerGui.RoundOver.RoundOver.Position = UDim2.new(2, 0,0.434, 0)
	wait(1)
	game.ReplicatedStorage.GameStarted.Value = false
	for i, plr in pairs(game.Players:GetPlayers()) do
		local Character = plr.Character
		if Character then
			local spawnpoint = game.ReplicatedStorage.ReturnSpawn:Clone()
			spawnpoint.Parent = workspace
			Character.HumanoidRootPart.Position = spawnpoint.Position
			spawnpoint:Destroy()
			game.ReplicatedStorage.AddCash:FireAllClients()
			end
		end
	else
		-- for this else I want it to end the "While true do" statement
	end


		mapclone:Destroy()
end
game.ReplicatedStorage.PlayersInRound.Value = 0``

look at the comment and see if you can help.

3 comments

0

If you want to end the loop, use 'break'

0

how do I use it?

0

Put "break" wherever you want the loop to immediately end

1 answer

Whenever you want to end the loop, type break and then it stops the loop and continues on with the code. You can use if conditions to make it end at a certain time or instance.

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