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

Why does the while wait() loop only run one time?

Asked by 3 years ago
function SaveData(character)
    local Data = {}
    local DaPlayer = Players:GetPlayerFromCharacter(character)
    character.Humanoid:UnequipTools()
    for i, v in pairs(DaPlayer.Backpack:GetChildren()) do
        if v:IsA("Tool") or v:IsA("LocalScript") then
            table.insert(Data, v.Name)
            print(v.Name)
        end
    end
    local UserId = "Player_"..DaPlayer.UserId
    local succ, err = pcall(function()
        DS:SetAsync(UserId, Data)
    end)
    if succ then
        print("Data Saved Sucessfully to"..DaPlayer.Name)
    else
        warn(err)
        print("Problem saving "..DaPlayer.Name.."'s Data")
    end
end

function teleport(Array)
    local ReserveCode = TS:ReserveServer(6981160086)
    TS:TeleportToPrivateServer(6981160086, ReserveCode, Array)
end

while wait() do
    for i, v in pairs(workspace:GetChildren()) do
        if v:FindFirstChild("Bending Sense") and v:FindFirstChild("MatchMaker") then
            table.insert(Potentials, v.Name)
            print("Added A Potential 1v1 Contester")
        end
    end
    if Potentials[2] ~= nil then
        print("Found Players to Teleport To Arena")
        local Chooser = math.random(1, #Potentials)
        local Character2Name = Potentials[Chooser]
        local Character2 = game.Workspace:FindFirstChild(Character2Name)
        repeat wait()
            local Chooser = math.random(1, #Potentials)     
            Character1Name = Potentials[Chooser]
        until Character1Name ~= Character2Name
        local Character1 = game.Workspace:FindFirstChild(Character1Name)
        SaveData(Character1)
        SaveData(Character2)
        wait(3)
        --wait(100)
        Player1 = Players:GetPlayerFromCharacter(Character1)
        Player2 = Players:GetPlayerFromCharacter(Character2)
        local Array = {Player1, Player2}
        teleport(Array)
        Player2 = nil
        Player1 = nil
        Potentials = {}
    else
        Potentials = {}
    end
end



0
if it runs all the way through one time maybe it gets stuck at the repeat? BulletproofVast 1033 — 3y

1 answer

Log in to vote
0
Answered by
valk_3D 140
3 years ago
Edited 3 years ago

use

while true do
    wait()
    --stuff here
end

While wait() do does not work because you need a condition which returns true or false to either keep the look running or end it.

Ad

Answer this question