Spawn npc's if there's less than 5 in workspace

so this script already prevents npc’s spawning if there’s any in workspace, but I want for it to spawn more if there’s 5 or less in workspace

local existingMinions = workspace:FindFirstChild("BludMinions")
		if existingMinions then
			Head.Sad:Play()
		else
1 Like

is it a local or a normal script ?

it’s a normal script. Located in ServerScriptService

do a folder where every blud minions will go

yeah what goes after that???

you need to do a in pairs thingy if you dont know what it is go ask to google me im not pretty good at scripting and i forgot what to do lol

I think you can do

 local existingMinions = workspace:FindFirstChild("BludMinions"):GetChildren()
		if #existingMinions < 5 then--if number of minions is folder is less than five, then

			Head.Sad:Play()
		else

This won’t work if you have something besides minions in the folder, you need npc’s ONLY in the folder, nothing else.

attempt to index nil with ‘GetChildren’

He thought that BludMinions was a folder for the minions *because it should be.

Though to fix what he assumed

local mins = 0
for _,v in pairs(workspace:GetChildren()) do
if v.Name == "BludMinions" then
mins += 1
end
end
if mins > 5 then
Head.Sad:Play()
end

1 Like

after some fixes for it to work with my script, and adding a folder this worked!

1 Like

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