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

How do you run a function a certain amount of times?

Asked by 4 years ago

I want to make my function, addplate(), to run as many times as the total number of values in my table. I've tried multiple ways but here's my best one. It only runs once. Line 38 was my attempt.

function addplate(player)
    local allplates = plates:GetChildren()
    local newplate = allplates[math.random(1, #allplates)]:clone()
    newplate.Parent = workspace.Plates
    newplate.Player.Value = player.Name
end

while true do
    print ("start")
    plateholder:ClearAllChildren()

    --Wait for players
    while true do
        wait(5)
        contestants = {}
        for _, player in pairs(game.Players:GetPlayers()) do
            if player and player.Character then
                local humanoid = player.Character:WaitForChild("Humanoid")
                if humanoid and humanoid.Health > 0 then
                    table.insert(contestants, player)
                end
            end
        end
        if #contestants >= 1 then
            break
        else
            statustag.Value = "Waiting for Players"
            timertag.Value = -1
        end
    end


    --Load Plates
    statustag.Value = "Loading Plates"
    timertag.Value = -1

    wait(2)
    for _, player in pairs(contestants) do
        addplate(player)
    statustag.Value = "Plates Loaded!"
    wait(3) 

Answer this question