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!
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 return
ing 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