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

I need some help with this function/loop?(unanswered)

Asked by
wjs3456 90
10 years ago

So I know I've asked a ton of questions on this but even though I have been tinkering around a lot with this script I need someone who knows what they're doing better than I do. Using this script I would like it to display a message when either the time runs out or they're are no "infected" players.

function survivor_finish(text,time)
    time_left = 20--just to test with
        while time_left >= 0 do
            time_left=time_left-1
            wait(1)
            print(time_left)
    if #getTeam(Game.Teams.Infected) == 0 or time_left==0 then
        m=Instance.new("Message",Workspace)
                m.Text = text
                wait(time)
                m:Destroy()
    end
    end
    end

survivor_finish("Time has run out, survivors win!",3)

Thanks!

1 answer

Log in to vote
-1
Answered by 10 years ago

this may work, it is better to use a for loop as it takes care of the need to minus one each time and just use time_left as usual

function survivor_finish(text,time) 
    for time_left=20,0,-1 do
        print(time_left)
            if #getTeam(Game.Teams.Infected) == 0 or time_left==0 then 
                    m=Instance.new("Message",Workspace)
                    m.Text = text
                    wait(time)
                    m:Destroy()
                end
            wait(1)
    end
end
survivor_finish("Time has run out, survivors win!",3) 
Ad

Answer this question