Why the countdown only works when all enemy spawn

i didnt what the issue is i tried using this script
local module = {}
local enemymodules = require(script.Parent.EnemyMobs)
local status = game.ReplicatedStorage.Status
local chosedmap = game.ReplicatedStorage.InRound.ChosedMap
local inround = game.ReplicatedStorage.InRound
local waiting = 1
local enemysspawns
local enemyfolder
local maps

module.ClassicMode = {
timer = function(round)
for i = round, 0, -1 do
wait(waiting)
maps = game.Workspace:FindFirstChild(chosedmap.Value)
status.Value = “Game will end in “…os.date(”%M:%S”, i)…" Minutes"
enemysspawns = maps.EnemySpawns:GetChildren()
enemyfolder = maps.Enemy
local playing = {}
for i, plr in pairs(game.Players:GetChildren()) do

			if plr.Team.Name == "Playing" then
				table.insert(playing, plr.Name)
				print("inserted player")
			end	
		end
		if i == 0  then
			status.Value = "A Madness Has Been Stopped"
		end
		if #playing == 0 then
			status.Value = "Everyone Has Died"
			wait(3)
			break
		end
		if i == 300  then
			enemymodules.Spawn("NPC", 24, enemysspawns, enemyfolder)
		end
	end
end,

}

return module
if your intresed of what the code inside enemymobs module
here it is
local EnemyMobs = {}
local serverstorage = game:GetService(“ServerStorage”)
local spawntimer = 0.3
local inround = game.ReplicatedStorage.InRound
function EnemyMobs.Spawn(name, quantity,spawner,files)
local mob = serverstorage.EnemyFolder:FindFirstChild(name)
if mob then
for i = 1, quantity do
task.wait(spawntimer)
local newmob = mob:Clone()
newmob.Parent = files
newmob.HumanoidRootPart.CFrame = spawner[math.random(1, #spawner)].CFrame
newmob.HumanoidRootPart:SetNetworkOwner(nil)
end
else
warn(“Mobs Are Not Existing”)
end
end
return EnemyMobs
can anyone tell me how to solve this?

Putting all of the code in a code block would help. One code block per Module/Script. You can click this button when making a post here on the forum, it gives a template for code:
image

It should automatically format the code. I’m having trouble formatting it myself as I’m having to make guesses as to what is indented and what isn’t.

okay but what do you mean by Putting all of the code in a code block would help?
i didnt understand about that

Like this:

Module Code:

local module = {}
local enemymodules = require(script.Parent.EnemyMobs)
local status = game.ReplicatedStorage.Status -- a string value
local chosedmap = game.ReplicatedStorage.InRound.ChosedMap -- an object value?
local inround = game.ReplicatedStorage.InRound -- no idea what this is, not used in code
local waiting = 1
local enemysspawns 
local enemyfolder
local maps

module.ClassicMode = {
	timer = function(round) -- I assume "round" is number greater than 0.
		for i = round, 0, -1 do -- Start = round, Goal = 0, iteration = -1
			wait(waiting)
			maps = game.Workspace:FindFirstChild(chosedmap.Value)
			status.Value = "Game will end in "..os.date("%M:%S", i).."Minutes"
			
			enemysspawns = maps.EnemySpawns:GetChildren() -- I assume this is a Folder that has Parts in it
			enemyfolder = maps.Enemy 
				
			local playing = {}
			for i, plr in pairs(game.Players:GetChildren()) do
				if plr.Team.Name == "Playing" then
					table.insert(playing, plr.Name)
					print("inserted player")
				end	
			end
				
			if i == 0  then -- when time is at 0..
				status.Value = "A Madness Has Been Stopped"
			end
			
			if #playing == 0 then -- this if-statement will be checked every second of the round
				status.Value = "Everyone Has Died"
				wait(3)
				break
			end
			
			if i == 300  then -- If "round" is not higher than 300, then this if-statement will not run. That might be an issue? Can't tell based on what I have avalible.
				enemymodules.Spawn("NPC", 24, enemysspawns, enemyfolder) -- this is fired when i = 300, so, based on the code from EnemyMobs, it would take 24 mobs 7.2 seconds to all spawn in. 1 mob every 0.3 seconds.
			end
			
		end
	end
}

return module

EnemyMobs Module Code:

local EnemyMobs = {}
local serverstorage = game:GetService("ServerStorage")
local spawntimer = 0.3
local inround = game.ReplicatedStorage.InRound

function EnemyMobs.Spawn(name, quantity,spawner,files)
	local mob = serverstorage.EnemyFolder:FindFirstChild(name)
	if mob then
		for i = 1, quantity do
			task.wait(spawntimer)
			local newmob = mob:Clone()
			newmob.Parent = files
			newmob.HumanoidRootPart.CFrame = spawner[math.random(1, #spawner)].CFrame
			newmob.HumanoidRootPart:SetNetworkOwner(nil)
		end
	else
		warn("Mobs Are Not Existing")
	end
end
return EnemyMobs

Issues with the OP itself:

I don’t mean to be that person, but the grammar here can be improved. The post itself too. This post should be under the #help-and-feedback:scripting-support category, not the #help-and-feedback:platform-usage-support category.

I find it difficult to actually find what the problem is because you didn’t describe it in the post itself. There was no mention of what you want the code to do, only what it currently does in the Title only.


My closing thoughts:

I have made comments in the code of the first Module, hope that helps. I do not see where a countdown only works when all enemies spawn.

My understanding of all of the code: The function(round) is called externally from the code I have available. → timer goes down, where it starts spawning enemies at i = 300, assuming “round” is greater than 300. → mobs are spawned using the EnemyMobs Module with a short delay.

robloxapp-20240601-1101571.wmv (2.7 MB)
okay you can watch this video so you understand whats the issue because i guess i have no proof. look at the countdown itll start after enemy stop spawning

okay nvm i solved by myself thanks for help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.