Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- ReturnSlide = game.ReplicatedStorage:findFirstChild("Return")
- Status = game.ReplicatedStorage:findFirstChild("Status")
- Wave = game.Workspace:findFirstChild("Wave")
- ZombieModel = game.Workspace:findFirstChild("Zombies")
- ------------------------------------------------------------------------------------------------------------
- function CheckAlive(player)
- local character = player.Character
- if (character == nil) then return false end
- if (character:findFirstChild("PlayerTag") == nil) then return false end
- local humanoid = character:findFirstChild("Humanoid")
- if (humanoid == nil) then return false end
- if (humanoid.Health == 0) then return false end
- return true
- end
- ------------------------------------------------------------------------------------------------------------
- -- Teleport Home
- function TeleportHome()
- local spawns = game.Workspace.Lobby:findFirstChild("Spawns"):GetChildren()
- if spawns then
- for i,players in pairs(game.Players:GetPlayers()) do
- local char = players.Character
- if char and char.Humanoid.Health > 0 and char.Torso and #spawns > 0 then
- local torso = char.Torso
- local spawnindex = math.random(1,#spawns)
- local chosenspawn = spawns[spawnindex]
- for i,spawn in pairs(spawns) do
- if spawns and torso and char.Humanoid.Health > 0 then
- table.remove(spawns, spawnindex)
- char:MoveTo(spawn.Position + Vector3.new(0,5,0))
- local pt = char:findFirstChild("PlayerTag")
- if pt then
- pt:destroy()
- end
- end
- end
- end
- end
- end
- end
- ------------------------------------------------------------------------------------------------------------
- -- Start Waves
- function aliveCheck()
- for i,v in ipairs(game.Players:GetPlayers()) do
- if v.Character and v.Character:FindFirstChild("PlayerTag") then
- --Player Alive
- return true
- end
- end
- return false
- end
- function StartWaves()
- Status:FireAllClients("Current Wave : ".. Wave.Value)
- if Wave.Value == 1 then
- for i,v in pairs(game.Players:GetPlayers()) do
- local char = v.Character
- if char then
- local pt = char:findFirstChild("PlayerTag")
- if pt == nil then
- char:MoveTo(game.Workspace.MapHolder.Map.Spawns.Spawn.Position)
- end
- end
- end
- end
- local neededzombies = Wave.Value * math.ceil(game.Players.NumPlayers / 2)
- local zombieskilled = 0
- for i = 1,neededzombies do
- wait(3.5)
- local zombies = game.ReplicatedStorage:findFirstChild("Zombies"):GetChildren()
- if zombies then
- local chooserandom = zombies[math.random(1,#zombies)]
- local chosenzombie = chooserandom:clone()
- chosenzombie:makeJoints()
- chosenzombie:MoveTo(game.Workspace.MapHolder.Map.ZombieSpawner.Position + Vector3.new(math.random(-15,15), 5, math.random(-15,15)))
- local stats = chosenzombie:findFirstChild("Stats")
- stats.Cash.Value = stats.Cash.Value + Wave.Value
- stats.Damage.Value = stats.Damage.Value + Wave.Value
- stats.Health.Value = 100 * Wave.Value
- stats.Speed.Value = stats.Speed.Value + Wave.Value / 5
- local health = stats.Health.Value
- chosenzombie.Zombie.MaxHealth = health
- chosenzombie.Zombie.Health = health
- chosenzombie.Zombie.WalkSpeed = stats.Speed.Value
- chosenzombie.Zombie.Died:connect(function()
- zombieskilled = zombieskilled + 1
- end)
- chosenzombie.Parent = game.Workspace:findFirstChild("Zombies")
- end
- end
- repeat wait() until neededzombies == zombieskilled or aliveCheck() == false
- print(neededzombies,zombieskilled)
- if aliveCheck() == false then
- Status:FireAllClients("All players killed!")
- TeleportHome()
- else
- Wave.Value = Wave.Value + 1
- ZombieModel:ClearAllChildren()
- StartWaves()
- end
- end
- ------------------------------------------------------------------------------------------------------------
- -- Random Return
- function Return()
- ReturnSlide:FireAllClients("")
- end
- ------------------------------------------------------------------------------------------------------------
- -- Checking to see if players are dead functions
- function CheckAllDead()
- local players = game.Players:getChildren()
- for i, player in ipairs(players) do
- if (CheckAlive(player)) then return false end
- end
- return true
- end
- ------------------------------------------------------------------------------------------------------------
- -- Intermission
- function Intermission()
- local timer = 2
- for i = 1,timer do
- timer = timer - 1
- Status:FireAllClients("Intermission : ".. timer)
- wait(1)
- end
- end
- ------------------------------------------------------------------------------------------------------------
- -- Load Map and teleport players into
- function LoadMap()
- Status:FireAllClients("Loading Map.")
- local map = game.ReplicatedStorage:findFirstChild("Part1"):clone()
- map.Parent = game.Workspace.MapHolder
- map.Name = "Map"
- wait(1)
- Status:FireAllClients("Loading Map..")
- wait(1)
- Status:FireAllClients("Loading Map...")
- local spawns = map:findFirstChild("Spawns"):GetChildren()
- if spawns then
- for i,players in pairs(game.Players:GetPlayers()) do
- local char = players.Character
- if char and char.Humanoid.Health > 0 and char.Torso and #spawns > 0 then
- local torso = char.Torso
- local PlayerTag = Instance.new("StringValue", char)
- PlayerTag.Name = "PlayerTag"
- if PlayerTag then
- local spawnindex = math.random(1,#spawns)
- local chosenspawn = spawns[spawnindex]
- for i,spawn in pairs(spawns) do
- if spawns and torso and char.Humanoid.Health > 0 then
- table.remove(spawns, spawnindex)
- char:MoveTo(spawn.Position + Vector3.new(0,5,0))
- end
- end
- end
- end
- end
- end
- end
- ------------------------------------------------------------------------------------------------------------
- -- Game Loop
- while true do
- wait()
- Intermission()
- wait(1)
- LoadMap()
- wait(1)
- Wave.Value = 1
- StartWaves()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement