Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

i need help makeing my zombies spawn in a wave of like 5 then wait then wave2?

Asked by 4 years ago
Edited 4 years ago

i tryed doing it but i just failed so i just made zombies spawn evry bit i need help makeing them in waves and add more zombies hears my script

local Path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(workspace.Start.Position,workspace.Wall.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("Enemies","Enemies",false) game:GetService("PhysicsService"):CollisionGroupSetCollidable("Players","Players",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 SpawnEnemy(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.Spawn.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.Wall.Health.Value = workspace.Wall.Health.Value - Enemy.Damage.Value
        Alive = false
        Enemy:Destroy()
    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()
    if Enemy.Health.Value < 0.1 then
        if Alive then
            Enemy:BreakJoints()
            Alive = false
            if Enemy.Head:FindFirstChild("Death") then
                Enemy.Head.Death:Play()
            end
            Bounty(Enemy)
            Enemy:Destroy() 
        end
        game.Debris:AddItem(Enemy,1)
    end
    Enemy.Humanoid.Health = (Enemy.Health.Value/Enemy.MaxHealth.Value) * 100
end)

for i,Part in pairs(Enemy:GetChildren()) do
    if Part:IsA("BasePart") then
        game:GetService("PhysicsService"):SetPartCollisionGroup(Part,"Enemies")
    end
end

if Enemy:FindFirstChild("WalkAnim") then
    local Track = Enemy.Humanoid:LoadAnimation(Enemy.WalkAnim)
    Track:Play()
--  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 -- its right hear i need help with! wait(1) local Chance = math.random(1,10) if Chance == 7 then SpawnEnemy("strong zombie") else SpawnEnemy("zombie") end

end

0
Mind making sure the question is more clear? iactz 15 — 4y
0
uh sorry it kind of choped up my script jablesgamer1 2 — 4y
0
it wont let me fix it jablesgamer1 2 — 4y
0
its at the bottom i need help with jablesgamer1 2 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You can put an inner loop inside the outer spawn loop to control how many zombies you want to spawn each time through the spawn loop. Something like this:

-- How long to wait between spawns
local timeBetweenSpawns = 10

-- How many zombies to spawn each wave
local zombiesToSpawn = 5

while true do
    for i = 1, zombiesToSpawn do
        local Chance = math.random(1,10)
        if Chance == 7 then
            SpawnEnemy("strong zombie")
        else
            SpawnEnemy("zombie")
        end
    end

    wait(timeBetweenSpawns)
end
0
ok thank you!!! jablesgamer1 2 — 4y
0
ok i will give you credit jablesgamer1 2 — 4y
0
um how can i get new zombies and more zombies evry wave? jablesgamer1 2 — 4y
Ad

Answer this question