Advertisement
HowToRoblox

GameHandler

Sep 1st, 2021 (edited)
5,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.01 KB | None | 0 0
  1. game.Players.PlayerAdded:Connect(function(plr)
  2.    
  3.     local ls = Instance.new("Folder")
  4.     ls.Name = "leaderstats"
  5.     ls.Parent = plr
  6.    
  7.     local cash = Instance.new("IntValue")
  8.     cash.Name = "Cash"
  9.     cash.Value = 0
  10.     cash.Parent = ls
  11. end)
  12.  
  13.  
  14. local collectionService = game:GetService("CollectionService")
  15.  
  16.  
  17. local gun = script:WaitForChild("Gun")
  18. local mobs = {[10] = script:WaitForChild("HardMob"), [5] = script:WaitForChild("MediumMob"), [1] = script:WaitForChild("EasyMob")}
  19.  
  20.  
  21. local mobSpawns = workspace:WaitForChild("MobSpawns")
  22.  
  23.  
  24. local statusValue = game.ReplicatedStorage:WaitForChild("StatusValue")
  25.  
  26.  
  27. local respawnWave = 3
  28.  
  29. local startingMobs = 5
  30.  
  31. local maxWave = math.huge
  32.  
  33.  
  34. while true do
  35.    
  36.    
  37.     statusValue.Value = "Intermission"
  38.    
  39.     for i, child in pairs(workspace:WaitForChild("MobsFolder"):getChildren()) do
  40.        
  41.         collectionService:RemoveTag(child, "mob")
  42.     end
  43.    
  44.     workspace.MobsFolder:ClearAllChildren()
  45.    
  46.     wait(5)
  47.    
  48.    
  49.     local alivePlrs = {}
  50.    
  51.     for i, plr in pairs(game.Players:GetPlayers()) do
  52.        
  53.         plr:LoadCharacter()
  54.        
  55.         table.insert(alivePlrs, plr)
  56.        
  57.         plr.Character.Humanoid.Died:Connect(function()
  58.             table.remove(alivePlrs, alivePlrs[plr])
  59.         end)
  60.        
  61.         gun:Clone().Parent = plr.Backpack
  62.     end
  63.    
  64.    
  65.     for i = 1, maxWave do
  66.        
  67.         local mobsToSpawn = (startingMobs / 2) * (2 ^ i)
  68.        
  69.         statusValue.Value = "Wave " .. i .. " starting."
  70.         wait(3)
  71.        
  72.        
  73.         local mobTypeSpawn
  74.         for waveNum, mobType in pairs(mobs) do
  75.            
  76.             if i >= waveNum then
  77.                
  78.                 mobTypeSpawn = mobType
  79.                 break
  80.             end
  81.         end
  82.        
  83.        
  84.         while mobsToSpawn > 0 do
  85.            
  86.             for x, spawner in pairs(mobSpawns:GetChildren()) do
  87.                
  88.                 mobsToSpawn = mobsToSpawn - 1
  89.                
  90.                 local mobClone = mobTypeSpawn:Clone()
  91.                 mobClone.HumanoidRootPart.CFrame = spawner.CFrame + Vector3.new(0, 10, 0)
  92.                
  93.                 mobClone.Humanoid.WalkSpeed = mobClone.Settings.Speed.Value
  94.                 mobClone.Humanoid.MaxHealth = mobClone.Settings.Health.Value
  95.                 mobClone.Humanoid.Health = mobClone.Humanoid.MaxHealth
  96.                
  97.                 collectionService:AddTag(mobClone, "mob")
  98.                
  99.                 mobClone.Humanoid.Died:Connect(function()
  100.                    
  101.                     collectionService:RemoveTag(mobClone, "mob")
  102.                    
  103.                     mobClone:Destroy()
  104.                 end)
  105.                
  106.                 mobClone.Parent = workspace:WaitForChild("MobsFolder")
  107.             end
  108.         end
  109.        
  110.         repeat
  111.             wait()
  112.            
  113.             statusValue.Value = "Wave " .. i .. " | " .. #workspace:WaitForChild("MobsFolder"):GetChildren() .. "/" .. (startingMobs / 2) * (2 ^ i) .. " Zombies"
  114.            
  115.         until #workspace:WaitForChild("MobsFolder"):GetChildren() < 1 or #alivePlrs < 1
  116.        
  117.         if #alivePlrs < 1 then
  118.             break
  119.            
  120.         else
  121.            
  122.             for y, plrAlive in pairs(alivePlrs) do
  123.                
  124.                 plrAlive.leaderstats.Cash.Value = plrAlive.leaderstats.Cash.Value + (20 * i)
  125.             end
  126.            
  127.             if i % respawnWave == 0 then
  128.                
  129.                 for z, plr in pairs(game.Players:GetPlayers()) do
  130.                    
  131.                     if not plr.Character then
  132.                        
  133.                         plr:LoadCharacter()
  134.                         gun:Clone().Parent = plr.Backpack
  135.  
  136.                         table.insert(alivePlrs, plr)
  137.                     end
  138.                 end
  139.             end
  140.         end
  141.     end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement