while wait() do
if (maxnumber.Value <= 1) then
return
else
local spawnLocation = ZombiesSpawns[math.random(1, #ZombiesSpawns)]
local Zombie = Zombies[math.random(1, #Zombies)]
local TpTo = nil
if spawnLocation:IsA("Part") or spawnLocation:IsA("SpawnLocation") then
TpTo = spawnLocation.Position
end
local new = Zombie:Clone()
new.Parent = ZombieCloningFolder
wait(.3)
new:MoveTo(TpTo)
maxnumber.Value = maxnumber.Value - 1local spawnLocation = ZombiesSpawns[math.random(1, #ZombiesSpawns)]
local Zombie = Zombies[math.random(1, #Zombies)]
local TpTo = CFrame.new(spawnLocation.Position)
local new = Zombie:Clone()
new.Parent = ZombieCloningFolder
new:SetPrimaryPartCFrame(TpTo.CFrame)
maxnumber.Value = maxnumber.Value - 1
end
end
local ZombieSpawnPointsFolder = Map:WaitForChild("ZombieSpawnPoints")
local ZombiesSpawns = ZombieSpawnPointsFolder:GetChildren()
local Difficultys = ReplicatedStorage:WaitForChild("Difficultys"):GetChildren()
local Difficulty = Difficultys[math.random(1, #Difficultys)]
local maxnumber = ReplicatedStorage:WaitForChild("MaxNumber")
local NewWaveEvent = ReplicatedStorage:WaitForChild("NewWave")
local WaveSystem = ReplicatedStorage:WaitForChild("WaveSystem")
local WaveNumber = WaveSystem:WaitForChild("TotalNumberOfWaves")
function NewWave() -- This is the function that errors --
if Difficulty.Value == 1 then
maxnumber.Value = 70
print("Zombies spawning: "..maxnumber.Value)
elseif Difficulty.Value == 2 then
maxnumber.Value = 80
print("Zombies spawning: "..maxnumber.Value)
elseif Difficulty.Value == 3 then
maxnumber.Value = 90
print("Zombies spawning: "..maxnumber.Value)
elseif Difficulty.Value == 4 then
maxnumber.Value = 100
print("Zombies spawning: "..maxnumber.Value)
elseif Difficulty.Value == 5 then
maxnumber.Value = 110
print("Zombies spawning: "..maxnumber.Value)
end
while wait() do
if (maxnumber.Value <= 1) then
return
else
local spawnLocation = ZombiesSpawns[math.random(1, #ZombiesSpawns)]
local Zombie = Zombies[math.random(1, #Zombies)]
local TpTo = nil
if spawnLocation:IsA("Part") or spawnLocation:IsA("SpawnLocation") then
TpTo = spawnLocation.Position
end
local TpTo = CFrame.new(spawnLocation.Position)
local new = Zombie:Clone()
new.Parent = ZombieCloningFolder
wait(.3)
new:MoveTo(TpTo)
maxnumber.Value = maxnumber.Value - 1
local spawnLocation = ZombiesSpawns[math.random(1, #ZombiesSpawns)]
local Zombie = Zombies[math.random(1, #Zombies)]
local TpTo = CFrame.new(spawnLocation.Position)
local new = Zombie:Clone()
new.Parent = ZombieCloningFolder
new:SetPrimaryPartCFrame(TpTo.CFrame)
maxnumber.Value = maxnumber.Value - 1
end
end
end
local spawnLocation = ZombiesSpawns[math.random(1, #ZombiesSpawns)]
local Zombie = Zombies[math.random(1, #Zombies)]
local TpTo = CFrame.new(spawnLocation.Position)
local new = Zombie:Clone()
new.Parent = ZombieCloningFolder
new:SetPrimaryPartCFrame(TpTo.CFrame)
maxnumber.Value = maxnumber.Value - 1
being repeated twice in almost the same way, wouldnāt it be simpler to do this?
while maxnumber.Value > 1 do
local spawnLocation = ZombiesSpawns[math.random(1, #ZombiesSpawns)]
local Zombie = Zombies[math.random(1, #Zombies)]
local TpTo = nil
if spawnLocation:IsA("Part") or spawnLocation:IsA("SpawnLocation") then
TpTo = spawnLocation.CFrame
local new = Zombie:Clone()
new.Parent = ZombieCloningFolder
wait(.3)
new:SetPrimaryPartCFrame(TpTo)
maxnumber.Value -= 1
end
wait()
end
And in terms of it not spawning more than once, maybe what I didāll help so it only decrements if the spawn is not a script