So when every player dies on the map the map is supposed to delete and the round restart. but when every player dies it doesnt
01 | local run = true |
02 | local Message = workspace.LobbyMessage |
03 | local start = true |
04 | while wait() do |
05 | local AlivePlayers = 0 |
06 | wait( 4 ) |
07 | if start then |
08 | start = false |
09 | Message.Text = "Preparing..." -- we'll get fancy with GUIs later |
10 | local maps = game.ReplicatedStorage.Maps:GetChildren() |
11 | Map = maps [ math.random( 1 ,#maps) ] |
12 | local NewMap = Map:Clone() |
13 | NewMap.Parent = workspace |
14 | wait( 1 ) |
15 | Message.Text = "" |
You're not continuously checking if all the players have died, so the if statement from line 29 to 35 won't execute at all if AlivePlayers is anything but 0. What we need to do is repeatedly check if AlivePlayers is under or equal to 0 (we do this so that if the game glitches at all, the game will reset without errors.)
To do this, you could use a repeat loop to wait until AlivePlayers is under or equal to 0 and use the built in spawn function so that the yielding from the repeat loop is done in a separate thread so other code can execute after it.
Code:
1 | spawn( function () --Spawn lets us create a new thread, so the code after this function will run without waiting for AlivePlayers to be under or equal to 0. |
2 | repeat wait() until AlivePlayers < = 0 --Waits until AlivePlayers is under or equal to 0. |
3 | run = false |
4 | Message.Text = "Everyone died... gg" |
5 | wait( 3 ) |
6 | Message.Text = "" |
7 | NewMap:Destroy() |
8 | end ) |
I hope my answer helped you. If it did, be sure to accept it.