Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(workspace.SpawningCircle.Position,workspace.TBD.Position + Vector3.new(3,0,0),500)
- local Positions = Path:GetPointCoordinates()
- math.randomseed(os.time())
- local EnemyGroup = game:GetService("PhysicsService"):CreateCollisionGroup("Enemies")
- local PlayerGroup = game:GetService("PhysicsService"):CreateCollisionGroup("Players")
- game:GetService("PhysicsService"):CollisionGroupSetCollidable("Enemies","Players",false)
- game:GetService("PhysicsService"):CollisionGroupSetCollidable("Players","Players",false)
- game:GetService("PhysicsService"):CollisionGroupSetCollidable("Enemies","Enemies",false)
- local function Bounty(Enemy)
- local Total = Enemy.Bounty.Value
- for i,Tag in pairs(Enemy.Credit:GetChildren()) do
- local Player = game.Players:FindFirstChild(Tag.Name)
- if Player then
- local Percent = Tag.Value / Enemy.MaxHealth.Value
- local Reward = math.ceil(Total * Percent)
- Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + Reward
- end
- end
- end
- local function CreateEnemy(Type)
- local Enemy = game.ServerStorage.Enemies:FindFirstChild(Type):Clone()
- local Alive = true
- Enemy.Parent = workspace.Enemies
- for i,Child in pairs(Enemy:GetChildren()) do
- if Child:IsA("BasePart") then
- Child.CanCollide = false
- end
- end
- local Objective
- Enemy.HumanoidRootPart.CFrame = workspace.SpawningCircle.CFrame + Vector3.new(math.random(-4,4),0,math.random(-4,4))
- local Index = 0
- local function NextObjective(Success)
- if Success then
- Index = Index + 1
- end
- if Positions[Index] then
- Enemy.Humanoid:MoveTo(Positions[Index])
- Objective = Positions[Index]
- else
- local Explode = Instance.new("Explosion",workspace)
- Explode.Position = Enemy.HumanoidRootPart.Position
- Explode.BlastPressure = 0
- workspace.TBD.Health.Value = workspace.TBD.Health.Value - Enemy.Damage.Value
- Alive = false
- Enemy:Destroy()
- end
- end
- NextObjective(true)
- Enemy.Humanoid.MoveToFinished:connect(function(Reached)
- if not Reached then
- if (Enemy.HumanoidRootPart.Position - Objective).magnitude < 4 then
- print("Reached limit of enimies LAG WILL INSUE")
- Reached = true
- end
- end
- NextObjective(Reached)
- end)
- Enemy.Health.Changed:connect(function() -- [C]
- if Enemy.Health.Value < 0 then
- if Alive then
- Enemy:BreakJoints()
- Alive = false
- if Enemy.Head:FindFirstChild("Death") then
- Enemy.Head.Death:Play() -- [C]
- end
- Bounty(Enemy)
- end
- game.Debris:AddItem(Enemy,1)
- end
- Enemy.Humanoid.Health = (Enemy.Health.Value/Enemy.MaxHealth.Value) * 100
- end)
- if Enemy:FindFirstChild("WalkAnim") then
- local Track = Enemy.Humanoid:LoadAnimation(Enemy.WalkAnim)
- Track:Play()
- end
- end
- wait(1)
- while true do
- wait(1)
- local Chance = math.random(1,15)
- if Chance == 5 then
- CreateEnemy("Enemy 1")
- else
- CreateEnemy("Enemy 2")
- if Chance == 4 then
- CreateEnemy("Enemy 3")
- else
- CreateEnemy("Enemy 4")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment