I’ve been trying to figure out this error for quite a while but I haven’t figured out the reason why it’s happening
It’s correct for a few seconds then it automatically goes below the number I allowed it by going negative and it turns out that it’ll always spawn 10 zombies no matter what then doubles it per wave
AdminCMDS:createCommand("zombiewaves", function(sender)
local MobsFolder = workspace:WaitForChild("CurrentMap"):WaitForChild("MobsFolder")
local mobs = {[10] = script:WaitForChild("Powered Up Zombie"), [5] = script:WaitForChild("Speedy"), [1] = script:WaitForChild("Regular Zombie")}
local mobSpawns = workspace:WaitForChild("CurrentMap"):WaitForChild("Map"):WaitForChild("MobSpawns")
local StatusValue = Instance.new("IntValue")
StatusValue.Parent = RPS:WaitForChild("Values")
StatusValue.Name = "StatusValue"
StatusValue.Value = 0
local SurvivorTeam = Instance.new("Team")
SurvivorTeam.Parent = game:GetService("Teams")
SurvivorTeam.AutoAssignable = false
SurvivorTeam.Name = "In-Game"
SurvivorTeam.TeamColor = BrickColor.new("Camo")
local Music = Instance.new("Sound")
Music.Parent = game:WaitForChild("Workspace")
Music.SoundId = "rbxassetid://7278145455"
Music:Play()
Music.Volume = 0.35
local respawnWave = 3
local startingMobs = 2
local maxWave = math.huge
for i, child in pairs(MobsFolder:getChildren()) do
CS:RemoveTag(child, "mob")
end
MobsFolder:ClearAllChildren()
task.wait(1)
local alivePlrs = {}
for i, plr in pairs(game.Players:GetPlayers()) do
coroutine.resume(coroutine.create(function()
plr.Team = SurvivorTeam
plr.TeamColor = SurvivorTeam.TeamColor
plr:LoadCharacter()
local LightingInstance = Instance.new("PointLight")
LightingInstance.Range = 15
LightingInstance.Color = Color3.fromRGB(255, 255, 255)
LightingInstance.Brightness = 2
LightingInstance.Enabled = true
LightingInstance.Parent = plr.Character.HumanoidRootPart
task.wait(0.1)
table.insert(alivePlrs, plr)
plr.Character.Humanoid.Died:Connect(function()
table.remove(alivePlrs, alivePlrs[plr])
plr.Team = game:GetService("Teams").Spectators
plr.TeamColor = game:GetService("Teams").Spectators.TeamColor
end)
end))
end
for i = 1, maxWave do
local mobsToSpawn = (startingMobs / 2) * (2 ^ i)
StatusValue.Value = i
task.wait(3)
TS:Create(LT, TweenInfo.new(0.4, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {ClockTime = 3.3}):Play()
local mobTypeSpawn
for waveNum, mobType in pairs(mobs) do
if i >= waveNum then
mobTypeSpawn = mobType
break
end
end
while mobsToSpawn >= 0 do
if mobsToSpawn >= 0 then
if mobsToSpawn < 0 then
mobsToSpawn = 0
end
for x, spawner in pairs(mobSpawns:GetChildren()) do
print(mobsToSpawn)
mobsToSpawn = mobsToSpawn - 1
local zombieClone = mobTypeSpawn:Clone()
zombieClone.HumanoidRootPart.CFrame = spawner.CFrame + Vector3.new(0, 10, 0)
zombieClone.Humanoid.WalkSpeed = zombieClone.Settings.Speed.Value
zombieClone.Humanoid.MaxHealth = zombieClone.Settings.Health.Value
zombieClone.Humanoid.Health = zombieClone.Humanoid.MaxHealth
CS:AddTag(zombieClone, "mob")
zombieClone.Humanoid.Died:Connect(function()
local creator = zombieClone.Humanoid:FindFirstChild("creator")
local DeathAnimation = script.ZombieSystem:WaitForChild("DeathAnimation")
local LoadAnimation = zombieClone.Humanoid:LoadAnimation(DeathAnimation)
CS:RemoveTag(zombieClone, "mob")
if creator and creator.ClassName == "ObjectValue" then
local killer = creator.Value
RPS:WaitForChild("Remotes"):WaitForChild("OnKill"):FireClient(killer, zombieClone.Name)
end
LoadAnimation:Play()
LoadAnimation.Stopped:wait()
zombieClone:Destroy()
end)
zombieClone.Parent = MobsFolder
end
end
task.wait(0.1)
end
repeat
task.wait()
StatusValue.Value = i
until #MobsFolder:GetChildren() < 1 or #alivePlrs < 1
if #alivePlrs < 1 then
for i, child in pairs(MobsFolder:getChildren()) do
CS:RemoveTag(child, "mob")
end
TS:Create(LT, TweenInfo.new(0.4, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {ClockTime = 7}):Play()
MobsFolder:ClearAllChildren()
SurvivorTeam:Destroy()
TS:Create(Music, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Volume = 0}):Play()
DB:AddItem(Music, 0.5)
break
else
if i % respawnWave == 0 then
for z, plr in pairs(game.Players:GetPlayers()) do
coroutine.resume(coroutine.create(function()
plr.Team = SurvivorTeam
plr.TeamColor = SurvivorTeam.TeamColor
plr:LoadCharacter()
task.wait(0.1)
table.insert(alivePlrs, plr)
end))
end
end
end
end
end)