Guest User

Untitled

a guest
Jul 5th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1.  
  2. local Path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(workspace.SpawningCircle.Position,workspace.TBD.Position + Vector3.new(3,0,0),500)
  3. local Positions = Path:GetPointCoordinates()
  4.  
  5. math.randomseed(os.time())
  6.  
  7. local EnemyGroup = game:GetService("PhysicsService"):CreateCollisionGroup("Enemies")
  8. local PlayerGroup = game:GetService("PhysicsService"):CreateCollisionGroup("Players")
  9. game:GetService("PhysicsService"):CollisionGroupSetCollidable("Enemies","Players",false)
  10. game:GetService("PhysicsService"):CollisionGroupSetCollidable("Players","Players",false)
  11. game:GetService("PhysicsService"):CollisionGroupSetCollidable("Enemies","Enemies",false)
  12.  
  13. local function Bounty(Enemy)
  14. local Total = Enemy.Bounty.Value
  15.  
  16. for i,Tag in pairs(Enemy.Credit:GetChildren()) do
  17. local Player = game.Players:FindFirstChild(Tag.Name)
  18. if Player then
  19. local Percent = Tag.Value / Enemy.MaxHealth.Value
  20. local Reward = math.ceil(Total * Percent)
  21. Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + Reward
  22. end
  23. end
  24. end
  25.  
  26. local function CreateEnemy(Type)
  27. local Enemy = game.ServerStorage.Enemies:FindFirstChild(Type):Clone()
  28. local Alive = true
  29. Enemy.Parent = workspace.Enemies
  30.  
  31. for i,Child in pairs(Enemy:GetChildren()) do
  32. if Child:IsA("BasePart") then
  33. Child.CanCollide = false
  34. end
  35. end
  36. local Objective
  37.  
  38. Enemy.HumanoidRootPart.CFrame = workspace.SpawningCircle.CFrame + Vector3.new(math.random(-4,4),0,math.random(-4,4))
  39. local Index = 0
  40.  
  41. local function NextObjective(Success)
  42. if Success then
  43. Index = Index + 1
  44. end
  45. if Positions[Index] then
  46. Enemy.Humanoid:MoveTo(Positions[Index])
  47. Objective = Positions[Index]
  48. else
  49. local Explode = Instance.new("Explosion",workspace)
  50. Explode.Position = Enemy.HumanoidRootPart.Position
  51. Explode.BlastPressure = 0
  52. workspace.TBD.Health.Value = workspace.TBD.Health.Value - Enemy.Damage.Value
  53. Alive = false
  54. Enemy:Destroy()
  55. end
  56. end
  57.  
  58. NextObjective(true)
  59. Enemy.Humanoid.MoveToFinished:connect(function(Reached)
  60.  
  61. if not Reached then
  62. if (Enemy.HumanoidRootPart.Position - Objective).magnitude < 4 then
  63. print("Reached limit of enimies LAG WILL INSUE")
  64. Reached = true
  65. end
  66. end
  67. NextObjective(Reached)
  68. end)
  69.  
  70. Enemy.Health.Changed:connect(function() -- [C]
  71. if Enemy.Health.Value < 0 then
  72. if Alive then
  73. Enemy:BreakJoints()
  74. Alive = false
  75. if Enemy.Head:FindFirstChild("Death") then
  76. Enemy.Head.Death:Play() -- [C]
  77. end
  78. Bounty(Enemy)
  79. end
  80. game.Debris:AddItem(Enemy,1)
  81. end
  82. Enemy.Humanoid.Health = (Enemy.Health.Value/Enemy.MaxHealth.Value) * 100
  83. end)
  84.  
  85.  
  86.  
  87. if Enemy:FindFirstChild("WalkAnim") then
  88. local Track = Enemy.Humanoid:LoadAnimation(Enemy.WalkAnim)
  89. Track:Play()
  90. end
  91. end
  92.  
  93.  
  94.  
  95. wait(1)
  96.  
  97.  
  98. while true do
  99. wait(1)
  100. local Chance = math.random(1,15)
  101. if Chance == 5 then
  102. CreateEnemy("Enemy 1")
  103. else
  104. CreateEnemy("Enemy 2")
  105.  
  106. if Chance == 4 then
  107. CreateEnemy("Enemy 3")
  108.  
  109. else
  110. CreateEnemy("Enemy 4")
  111. end
  112.  
  113. end
  114.  
  115. end
Advertisement
Add Comment
Please, Sign In to add comment