So, I’m trying to make a zombie game with waves, and it isn’t working. I can’t get a players death to make a game start over, because of whatever thing. I tried a player on died, look if the alive players changed, nothing worked. I’m getting annoyed due to this.
local spawns = workspace.ZombieSpawns:GetChildren()
local waves = 2
local zombie = game.ReplicatedStorage.Zombie
local zombies = 0
local gameInProgress = workspace.gameInProgress.Value
local wave = workspace.Wave
local zombiesAlive = workspace.zombiesAlive
local zombieCount = workspace.zombieCount
local alive = workspace.AlivePlayers.Value
function deathcheck()
for i,v in pairs(game.Players:GetPlayers()) do
v.Character.Humanoid.Died:Connect(function()
if v.Alive.Value == true and alive > 0 then
alive = alive -1
v.Alive.Value = false
print(alive)
end
end)
end
end
function spawnzombies()
for i = 1,zombieCount.Value do
wait(1)
local choice = spawns[math.random(1,#spawns)]
local spawned = zombie
spawned:Clone().Parent = workspace
spawned.HumanoidRootPart.Position = Vector3.new(workspace.ZombieSpawns[choice.Name].Position.X,workspace.ZombieSpawns[choice.Name].Position.Y,workspace.ZombieSpawns[choice.Name].Position.Z)
end
end
function startmap()
workspace.bass:Play()
wait(1)
workspace.bass:Play()
wait(1)
workspace.bass2:Play()
wait(1)
for i,v in pairs(game.Players:GetPlayers()) do
v.Character.Torso.Position = Vector3.new(0, 10, 0)
alive = i
v.Alive.Value = true
end
print(alive)
gameInProgress = true
workspace.lobbyTheme:Play()
zombieCount.Value = 6
zombiesAlive.Value = 6
wave.Value = 1
gameInProgress = true
spawnzombies()
deathcheck()
repeat
if zombiesAlive.Value == 0 and gameInProgress == true then
wave.Value = wave.Value + 1
zombieCount.Value = 6 * wave.Value
zombiesAlive.Value = 6 * wave.Value
spawnzombies()
end
wait() until gameInProgress == false or alive == 0
end
function fail()
print("die")
gameInProgress = false
workspace.Zombies:ClearAllChildren()
wave = 0
zombieCount.Value = 0
zombiesAlive.Value = 0
workspace.lobbyTheme:Stop()
wait(5)
startmap()
end
wait()
startmap()