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
local run = true
local Message = workspace.LobbyMessage
local start = true
while wait() do
local AlivePlayers = 0
wait(4)
if start then
start = false
Message.Text = "Preparing..." -- we'll get fancy with GUIs later
local maps = game.ReplicatedStorage.Maps:GetChildren()
Map = maps[math.random(1,#maps)]
local NewMap = Map:Clone()
NewMap.Parent = workspace
wait(1)
Message.Text = ""
for i,players in pairs(game.Players:GetPlayers()) do
AlivePlayers = game.Players.NumPlayers
players.Character.Humanoid.Died:connect(function()
AlivePlayers = AlivePlayers - 1
end)
players.Character.Torso.CFrame = CFrame.new(NewMap.Start.Position.X+i,NewMap.Start.Position.Y+12,NewMap.Start.Position.Z+i)
players.Character.Humanoid.WalkSpeed = 0
wait(2)
Message.Text = "GO"
players.Character.Humanoid.WalkSpeed = 50
wait(.3)
Message.Text = ""
end
if AlivePlayers == 0 then
run = false
Message.Text = "Everyone died... gg"
wait(3)
Message.Text = ""
NewMap:Destroy()
end
NewMap.End.Touched:connect(function(It)
if run == true then
start = true
local spawn = workspace.SpawnLocation
local player = game.Players:GetPlayerFromCharacter(It.Parent)
print("waiting")
for i,players in pairs(game.Players:GetPlayers()) do
players.Character.Torso.CFrame = CFrame.new(spawn.Position.X+i,spawn.Position.Y+12,spawn.Position.Z+i)
workspace.LobbyMessage.Text = (player.Name.." Has won")
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value+50
NewMap:Destroy()
wait(3)
workspace.LobbyMessage.Text = ("")
wait(5)
end
end
end)
end
end

1 comment
there are no errors