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

How do i stop this bit of code from running?

Asked by
Damo999 182
10 years ago

if there is less than 2 players how would i stop the script from running until there is enough.

game.Players.PlayerAdded:connect(function()
    if game.Players.NumPlayers < 2 then 
        mm = Instance.new("Message",Workspace)
        mm.Text = "Not enough players"
        wait(1)
        mm:Remove()
    else
        if game.Players.NumPlayers >= 2 then
        mmm = Instance.new("Message",Workspace)
        mmm.Text = "enough players"
        wait(1)
        mmm:Remove()
        script:Remove()
        end
    end -- around here
    m = Instance.new("Message",Workspace)
    m.Text = "You are Chosen"
    wait(5)
    m:Remove()
    players = game.Players:GetPlayers()
    killer = players[math.random(1,#players)]
    print("You are chosen")
end)

1 answer

Log in to vote
0
Answered by 10 years ago

Use repeat. The following code waits until the given amount of players are there.

repeat wait() until game.Players.NumPlayers > 2
Ad

Answer this question