Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(workspace.Start.Position,workspace.Wall.Position+ Vector3.new(3,0,0),500) -- PathFinding
- local Positions = Path:GetPointCoordinates()
- --[[ = Vector3.new(0, 0, 0)
- x = 200 -- range from origin
- y = 15 -- whatever height you want
- p = part
- ]]--
- math.randomseed(os.time())-- No Clue
- -- Variables
- RSP = math.random(1,360)
- 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) -- Controls the Leaderboard and buying fuction for towers. E.g., "50 Cash" Remember to add UNITS LATER!
- 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
- -- CODE SEPERATOR --
- local function SpawnEnemy(Type) -- whenever SpawnEnemy is used, play everything below.
- local Enemy = game.ServerStorage.Enemies:FindFirstChild(Type):Clone() -- Variable for Enemy, find the Enemy folder get the Firsh Child, then clone.
- local Alive = true -- Variable for true.
- Enemy.Parent = workspace.Enemies -- Variable for Enemy.Parent as the enimes in reality.
- for i,Child in pairs(Enemy:GetChildren()) do -- for the Enemy's children
- if Child:IsA("BasePart") then -- if Enemy's Children are BaseParts then
- Child.CanCollide = false -- set colliable to false
- end
- end
- local Objective -- Variable for Objective
- local RSP = math.random(1,3)
- if RSP == 1 then
- ABC = workspace.ABC1
- else ABC = workspace.ABC2
- if RSP == 3 then
- ABC = workspace.ABC3
- end
- end
- Enemy.HumanoidRootPart.CFrame = ABC.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 -- [B]
- Enemy.Humanoid:MoveTo(Positions[Index])
- Objective = Positions[Index]
- else
- local Explode = Instance.new("Explosion",workspace)
- Explode.Position = Enemy.HumanoidRootPart.Position
- Explode.BlastPressure = 0
- workspace.Wall.Health.Value = workspace.Wall.Health.Value - Enemy.Damage.Value
- Alive = false
- Enemy:Destroy() -- [B]
- end
- end
- NextObjective(true)
- Enemy.Humanoid.MoveToFinished:connect(function(Reached)
- -- if they are *close enough* consider it as good as the real deal?
- if not Reached then
- if (Enemy.HumanoidRootPart.Position - Objective).magnitude < 4 then
- print("Reached override")
- Reached = true
- end
- end
- NextObjective(Reached)
- end)
- Enemy.Health.Changed:connect(function() -- When the enimies health is changed, and the connection is etablished:
- if Enemy.Health.Value < 0 then -- if Enemy's health lower than 0 then
- if Alive then -- if its health is lower than 0, and it's alive then
- Enemy:BreakJoints() -- break joints of enemy or delete joints to be more specific.
- Alive = false -- then change alive to false.
- if Enemy.Head:FindFirstChild("Death") then -- then find the first child of the Head of the enemy, if it's the Death sound then
- Enemy.Head.Death:Play() -- play the death noise
- end
- Bounty(Enemy) -- Set the bounty of the enemy when killed by a tower.
- end
- game.Debris:AddItem(Enemy,1) -- ?????
- end
- Enemy.Humanoid.Health = (Enemy.Health.Value/Enemy.MaxHealth.Value) * 100 -- The enimies health is = to max health divided by MaxHealth value, times 100.
- end)
- for i,Part in pairs(Enemy:GetChildren()) do -- for the Part, find the enimies children
- if Part:IsA("BasePart") then -- If the part is a base part, then,
- game:GetService("PhysicsService"):SetPartCollisionGroup(Part,"Enemies") -- then, set the base part/part to be collideable with enimies.
- end -- Ends
- end -- Ends
- if Enemy:FindFirstChild("WalkAnim") then -- If the Enimies first child is the WalkAnim animation then
- local Track = Enemy.Humanoid:LoadAnimation(Enemy.WalkAnim) -- then, track the Enemy, and load the Animation
- Track:Play() -- play the animation while tracking ^^^^^^
- -- Enemy.WalkAnim:Play()
- end
- end
- wait(1)
- for i,Wall in pairs(workspace.Path.Walls:GetChildren()) do
- if Wall.Name == "Wall" and Wall:IsA("BasePart") then
- Wall.Transparency = 1
- Wall.CanCollide = false
- end
- end
- while true do
- wait(1)
- local Chance = math.random(1,10)
- if Chance == 7 then
- SpawnEnemy("Rich Dummy")
- else
- SpawnEnemy("Dummy")
- if Chance == 4 then
- SpawnEnemy("TestEnemy01")
- else
- SpawnEnemy("Dummy02")
- end
- end
- end
- --[[while true do
- wait(2)
- local value = math.random(-200, 200), 15, math.random(-200, 200)
- local model = game.ServerStorage.Enemies:FindFirstChild(Type) :Clone()
- Enemy:MoveTo(Vector3.new(value))
- model:MoveTo(Vector3.new (value))
- end
- --]]
Advertisement
Add Comment
Please, Sign In to add comment