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

How do I make a countdown?

Asked by 9 years ago

In this script how do I make a countdown so I can connect it to a string?

wait(1)
function movePlayers()--Don't mess with this
    local player = game.Players:GetPlayers()
    for i = 1, #player do
        player[i].Character:MoveTo(Vector3.new(-16, 0.5, -48))
    end

end


game.Players.PlayerAdded:connect(function(char)

    local hint = Instance.new("Hint")
        for i = 30, 1, -1 do
        repeat wait(1)
        if game.Players.NumPlayers >= 2 then--Change the 2 to the number of players you want to start the game
        hint.Parent = game.Workspace
        hint.Text = ("Starting the game in "..i.." seconds")--I want to have it as ("Starting game in "..i.." seconds")
        else
        hint.Text = ("Waiting for players...")
        end
        until i == 0
        movePlayers()
        hint.Parent = game.Lighting
        end
end)

1 answer

Log in to vote
0
Answered by 9 years ago
wait(1)
function movePlayers()--Don't mess with this
    local player = game.Players:GetPlayers()
    for i = 1, #player do
        player[i].Character:MoveTo(Vector3.new(-16, 0.5, -48))
    end

end


game.Players.PlayerAdded:connect(function(char)
        if game.Players.NumPlayers >= 2 then
    local hint = Instance.new("Hint", workspace)
i = 30       
repeat
wait(1)
        hint.Text = ("Starting the game in "..i.." seconds")--I want to have it as ("Starting game in "..i.." seconds")
i = i-1
        until i <= 0
        movePlayers()
        hint.Parent = nil --Use parent = nil if you want to "remove" the hint. But you're able to bring it back.
        else
        hint.Text = ("Waiting for players...")
        end

end)

Use a repeat instead of for i = 30,1,-1.

Ad

Answer this question