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

Is there a fix?

Asked by
wjs3456 90
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Please tab your code properly.


Since the if for ending the game doesn't actually stop the loop, the loop will just keep going if all Infected are gone.

We need to add a return or a break to make it stop.

I suggest returning the team that won:

function waitForWinner(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  then
            return game.Teams.Survivors;
        end
    end
    return game.Teams.Infected;
end

local winner = waitForWinner();

I am assuming Survivors is the name of the team that opposes Infected (and that there is an opposing team) and that Infected wins if the time runs out.

I would suggest moving the message creation to deal with winner rather than to actually be done inside this function. It should keep things cleaner and easier to understand.

Those might not be correct assumptions but it should be easy to tweak this to fit your game!

Fixed typo in condition; time_left == 0 shouldn't have been a check for the other team winning

0
Can you describe what this does maybe? wjs3456 90 — 9y
1
There are 20 seconds per round; if all the Infected die, we say "survivors" wins; otherwise "infected" win. Though I just realized I had a mistake in the condition on line 7, sorry about that, it's fixed now BlueTaslem 18071 — 9y
0
Can I make it so it is checking for a winner during the while loop? wjs3456 90 — 9y
1
Of course, that is what this is doing currently, and you could also add additional conditions. BlueTaslem 18071 — 9y
View all comments (2 more)
0
It seems to wait for the time to be over for the message to be displayed. I'll check again. wjs3456 90 — 9y
0
Yeah it waits for the time to end then it displays the message wjs3456 90 — 9y
Ad

Answer this question