i tried to make a script that would cap the amount of npcs spawned to the amount of players
local NPC = game.ReplicatedStorage.Gunman
local spawner = script.Parent
local player_count = #game:GetService(“Players”):GetPlayers()
local npc_count = #workspace:FindFirstChild(“gunman”)
while true do
local Clone = NPC:Clone()
Clone.Torso.CFrame = spawner.CFrame
Clone.Parent = workspace
if player_count == 1 then
if npc_count == 5 then
break
end
end
end
local Players = game:GetService("Players")
local NPC_Count = 0
local function createNPC() -- I recommend making an NPC class, and making this a method
NPC_Count += 1
local Clone = NPC:Clone()
Clone.Torso.CFrame = spawner.CFrame
Clone.Parent = workspace
end
local function update()
local playerCount = #Players:GetPlayers()
while NPC_Count < playerCount do
createNPC()
task.wait()
end
end