Trying to check the amount of children in a folder

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to add a limit to how much enemies can spawn.

  2. What is the issue? It isn’t counting the children in the folder.

  3. What solutions have you tried so far? I have looked for solutions but none of them worked or they were just the same thing I did

Yes there are enemies parented to activeEnemies and I have also called the function

local prepareLength = 1
local messageLength = 10

local inRound = game.ReplicatedStorage.RoundValues.InRound
local status = game.ReplicatedStorage.RoundValues.Status
local roundTime = game.ReplicatedStorage.RoundValues.RoundTime
local enemies = game.ServerStorage.Enemys:GetChildren()
local enemySpawns = game.Workspace.EnemySpawns:GetChildren()
local activeEnemies = game.Workspace.Enemys:GetChildren()

function spawnWave()
	if #activeEnemies < 40 then -- Part that is not working
		for i = 10, 0, -1 do

			local enemyClone = enemies[math.random(1, #enemies)]:Clone()
			enemyClone.Parent = workspace.Enemys
			enemyClone:SetPrimaryPartCFrame(enemySpawns[math.random(1, #enemySpawns)].CFrame)

		end
		print(#activeEnemies)
	end
end
	

because you call GetChildren() at the start of the script, and the folder at the start is 95% empty, meaning it’s just gonna be empty

just print the amount of active enemies in the function to see if it’s accurate

You’re created a static array by recording the children at a point in time. This does not update the array as the children change. If you want to know the current number of children, you’ll need to call GetChildren again

don’t know how i didn’t notice that lol