Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to cut a "While true do" loop short?

Asked by 1 year ago
Edited by Xapelize 1 year ago

I've asked this before but I feel like I wasn't clear about what I wanted. basically I want somewhere in my code to stop the loop but start it from the beginning.

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
-- here I want it to cut the loop short but continue looping


    end



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

look at the comment and try to help! Thanks

1
Please format your code better! MattVSNNL 620 — 1y
0
how I tried it did not work masilasi2008 10 — 1y
0
i fixed the code format Xapelize 2658 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

Just use

break

at the line where you want to stop the loop

Ad

Answer this question