How to make a npc attack multiple people at once

im still stuck on this part, any answer would be appreacheated

You may be dealing with this error because of your Module, take a look if there are any cooldowns there.

there is, but is there any possible way to make it so that it like astablice the cooldown but fires multiple attacks at once?

You would have to do this cooldown in the script before calling the module

in this case, I would recommend doing a specific cooldown for which NPC used it and which “random” is on cooldown

try wrapping each call in task.spawn()

task.spawn(function() modelu.GasterBlaster(script.Parent.HumanoidRootPart, humanoidrootpart) end)
task.spawn(function() modelu.BoneThrow(script.Parent.HumanoidRootPart, humanoidrootpart) end)
task.spawn(function() modelu.BoneZone(script.Parent.HumanoidRootPart, humanoidrootpart) end)
task.spawn(function() modelu.Quad(script.Parent.HumanoidRootPart, humanoidrootpart) end)
task.spawn(function() modelu.RandomBlast(script.Parent.HumanoidRootPart, humanoidrootpart) end)
1 Like

i dont understand, im guessing what your trying to say is to remove the cooldown from the module and add the cooldowns myself in the npcai script which calls the module and add it manualy, am i right?

exactly, I’m making changes, just a minute.

local rep = game.ReplicatedStorage
local humanoid = script.Parent.Humanoid
local maxdistance = 100
local mindistance = 50
local died = script.Parent.Dead

humanoid.Died:Connect(function()
	print("Died")
	died.Value = true
end)

local modelu = require(script.ModuleScript)

local Cooldowns = {}
local AttackComb = {
	{
		Cooldown_Timer = 1,
		Attacks = {
			modelu.GasterBlaster, -- You can add more attacks to the table to apply at the same time.
		}
	},
	{
		Cooldown_Timer = 1,
		Attacks = {
			modelu.BoneThrow, -- You can add more attacks to the table to apply at the same time.
		}
	},
	{
		Cooldown_Timer = 1,
		Attacks = {
			modelu.BoneZone, -- You can add more attacks to the table to apply at the same time.
		}
	},
	{
		Cooldown_Timer = 1,
		Attacks = {
			modelu.Quad, -- You can add more attacks to the table to apply at the same time.
		}
	},
	{
		Cooldown_Timer = 1,
		Attacks = {
			modelu.RandomBlast, -- You can add more attacks to the table to apply at the same time.
		}
	},
}

while task.wait(0.5) do
	local playersInRange = {}

	for _, player in pairs(game:GetService("Players"):GetPlayers()) do
		if player and player.Character then
			local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
			if humanoidRootPart and player.Character:FindFirstChild("Humanoid") then
				local distance = (humanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).magnitude
				if distance < maxdistance then
					table.insert(playersInRange, {player = player, distance = distance})
				end
			end
		end
	end

	local AttackComb_Selected = nil

	-- Apply Cooldown and select attack
	local RandomizeAttacks = table.clone(AttackComb)
	repeat
		if #RandomizeAttacks == 0 then break end

		local random = math.random(1,#RandomizeAttacks)
		local TryingTab = AttackComb[random]


		if Cooldowns[tostring(TryingTab)] then
			table.remove(RandomizeAttacks,random)
			continue
		end

		Cooldowns[tostring(random)] = true
		task.delay(TryingTab.Cooldown_Timer or 1,function()
			Cooldowns[tostring(random)] = nil
		end)
		
		AttackComb_Selected = TryingTab
		break
	until #RandomizeAttacks == 0

	if AttackComb_Selected then -- If you have any attacks you can use.
		for _, playerInfo in pairs(playersInRange) do
			local player = playerInfo.player
			local distance = playerInfo.distance

			if distance <= mindistance and not died.Value then
				local humanoidrootpart = player.Character:FindFirstChild("HumanoidRootPart")

				if humanoidrootpart then
					for _,ModuleFunc in pairs(AttackComb_Selected.Attacks or {}) do
						task.spawn(ModuleFunc,script.Parent.HumanoidRootPart, humanoidrootpart)
					end
				end
			end
		end
	end


	if #playersInRange > 0 then
		local closestPlayer = playersInRange[1].player
		local closestDistance = playersInRange[1].distance

		for _, playerInfo in pairs(playersInRange) do
			if playerInfo.distance < closestDistance then
				closestPlayer = playerInfo.player
				closestDistance = playerInfo.distance
			end
		end

		if closestPlayer.Character then
			local closestHumanoidRootPart = closestPlayer.Character:FindFirstChild("HumanoidRootPart")
			if closestHumanoidRootPart then
				humanoid:MoveTo(closestHumanoidRootPart.Position)
			end
		end
	end
end

I’m not sure I understood what you wanted, but now you should be able to do combos and use the same skills on all players. Remember to remove the cooldown in your ModuleScript.

You can set unique ranges for each attack or combo if you want.

thanks but uhhh, this ended up happening but it worked well, also @ETNowis helped along so i would like to take a moment to thank you all for helping me fix a script
Watch robloxapp-20250129-2352599 | Streamable