Advertisement
WishNite

Untitled

Dec 21st, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. -- Variables
  2.  
  3.  
  4. ReturnSlide = game.ReplicatedStorage:findFirstChild("Return")
  5. Status = game.ReplicatedStorage:findFirstChild("Status")
  6. Wave = game.Workspace:findFirstChild("Wave")
  7. ZombieModel = game.Workspace:findFirstChild("Zombies")
  8.  
  9. ------------------------------------------------------------------------------------------------------------
  10.  
  11. function CheckAlive(player)
  12. local character = player.Character
  13. if (character == nil) then return false end
  14. if (character:findFirstChild("PlayerTag") == nil) then return false end
  15. local humanoid = character:findFirstChild("Humanoid")
  16. if (humanoid == nil) then return false end
  17. if (humanoid.Health == 0) then return false end
  18. return true
  19. end
  20.  
  21.  
  22. ------------------------------------------------------------------------------------------------------------
  23. -- Teleport Home
  24.  
  25. function TeleportHome()
  26. local spawns = game.Workspace.Lobby:findFirstChild("Spawns"):GetChildren()
  27. if spawns then
  28. for i,players in pairs(game.Players:GetPlayers()) do
  29. local char = players.Character
  30. if char and char.Humanoid.Health > 0 and char.Torso and #spawns > 0 then
  31. local torso = char.Torso
  32. local spawnindex = math.random(1,#spawns)
  33. local chosenspawn = spawns[spawnindex]
  34. for i,spawn in pairs(spawns) do
  35. if spawns and torso and char.Humanoid.Health > 0 then
  36. table.remove(spawns, spawnindex)
  37. char:MoveTo(spawn.Position + Vector3.new(0,5,0))
  38. local pt = char:findFirstChild("PlayerTag")
  39. if pt then
  40. pt:destroy()
  41. end
  42. end
  43. end
  44. end
  45. end
  46. end
  47. end
  48.  
  49. ------------------------------------------------------------------------------------------------------------
  50. -- Start Waves
  51.  
  52.  
  53.  
  54. function aliveCheck()
  55. for i,v in ipairs(game.Players:GetPlayers()) do
  56. if v.Character and v.Character:FindFirstChild("PlayerTag") then
  57. --Player Alive
  58. return true
  59. end
  60. end
  61. return false
  62. end
  63.  
  64.  
  65. function StartWaves()
  66. Status:FireAllClients("Current Wave : ".. Wave.Value)
  67.  
  68. if Wave.Value == 1 then
  69. for i,v in pairs(game.Players:GetPlayers()) do
  70. local char = v.Character
  71. if char then
  72. local pt = char:findFirstChild("PlayerTag")
  73. if pt == nil then
  74. char:MoveTo(game.Workspace.MapHolder.Map.Spawns.Spawn.Position)
  75. end
  76. end
  77. end
  78. end
  79.  
  80. local neededzombies = Wave.Value * math.ceil(game.Players.NumPlayers / 2)
  81. local zombieskilled = 0
  82. for i = 1,neededzombies do
  83. wait(3.5)
  84. local zombies = game.ReplicatedStorage:findFirstChild("Zombies"):GetChildren()
  85. if zombies then
  86. local chooserandom = zombies[math.random(1,#zombies)]
  87. local chosenzombie = chooserandom:clone()
  88. chosenzombie:makeJoints()
  89. chosenzombie:MoveTo(game.Workspace.MapHolder.Map.ZombieSpawner.Position + Vector3.new(math.random(-15,15), 5, math.random(-15,15)))
  90. local stats = chosenzombie:findFirstChild("Stats")
  91. stats.Cash.Value = stats.Cash.Value + Wave.Value
  92. stats.Damage.Value = stats.Damage.Value + Wave.Value
  93. stats.Health.Value = 100 * Wave.Value
  94. stats.Speed.Value = stats.Speed.Value + Wave.Value / 5
  95. local health = stats.Health.Value
  96. chosenzombie.Zombie.MaxHealth = health
  97. chosenzombie.Zombie.Health = health
  98. chosenzombie.Zombie.WalkSpeed = stats.Speed.Value
  99. chosenzombie.Zombie.Died:connect(function()
  100. zombieskilled = zombieskilled + 1
  101. end)
  102. chosenzombie.Parent = game.Workspace:findFirstChild("Zombies")
  103. end
  104. end
  105.  
  106. repeat wait() until neededzombies == zombieskilled or aliveCheck() == false
  107. print(neededzombies,zombieskilled)
  108. if aliveCheck() == false then
  109. Status:FireAllClients("All players killed!")
  110. TeleportHome()
  111. else
  112. Wave.Value = Wave.Value + 1
  113. ZombieModel:ClearAllChildren()
  114. StartWaves()
  115. end
  116. end
  117.  
  118.  
  119.  
  120. ------------------------------------------------------------------------------------------------------------
  121. -- Random Return
  122.  
  123. function Return()
  124. ReturnSlide:FireAllClients("")
  125. end
  126.  
  127.  
  128. ------------------------------------------------------------------------------------------------------------
  129. -- Checking to see if players are dead functions
  130.  
  131.  
  132. function CheckAllDead()
  133. local players = game.Players:getChildren()
  134. for i, player in ipairs(players) do
  135. if (CheckAlive(player)) then return false end
  136. end
  137. return true
  138. end
  139.  
  140.  
  141. ------------------------------------------------------------------------------------------------------------
  142. -- Intermission
  143.  
  144. function Intermission()
  145. local timer = 2
  146. for i = 1,timer do
  147. timer = timer - 1
  148. Status:FireAllClients("Intermission : ".. timer)
  149. wait(1)
  150. end
  151. end
  152.  
  153.  
  154. ------------------------------------------------------------------------------------------------------------
  155. -- Load Map and teleport players into
  156.  
  157. function LoadMap()
  158. Status:FireAllClients("Loading Map.")
  159. local map = game.ReplicatedStorage:findFirstChild("Part1"):clone()
  160. map.Parent = game.Workspace.MapHolder
  161. map.Name = "Map"
  162. wait(1)
  163. Status:FireAllClients("Loading Map..")
  164. wait(1)
  165. Status:FireAllClients("Loading Map...")
  166. local spawns = map:findFirstChild("Spawns"):GetChildren()
  167. if spawns then
  168. for i,players in pairs(game.Players:GetPlayers()) do
  169. local char = players.Character
  170. if char and char.Humanoid.Health > 0 and char.Torso and #spawns > 0 then
  171. local torso = char.Torso
  172. local PlayerTag = Instance.new("StringValue", char)
  173. PlayerTag.Name = "PlayerTag"
  174. if PlayerTag then
  175. local spawnindex = math.random(1,#spawns)
  176. local chosenspawn = spawns[spawnindex]
  177. for i,spawn in pairs(spawns) do
  178. if spawns and torso and char.Humanoid.Health > 0 then
  179. table.remove(spawns, spawnindex)
  180. char:MoveTo(spawn.Position + Vector3.new(0,5,0))
  181. end
  182. end
  183. end
  184. end
  185. end
  186. end
  187. end
  188.  
  189.  
  190.  
  191. ------------------------------------------------------------------------------------------------------------
  192. -- Game Loop
  193.  
  194. while true do
  195. wait()
  196. Intermission()
  197. wait(1)
  198. LoadMap()
  199. wait(1)
  200. Wave.Value = 1
  201. StartWaves()
  202. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement