This function only runs for the first NPC? I have no idea why!

so I followed this tutorial by TapWater.

And it works!
Only problem is for my script it is not working how I want it to:
So it should do this three times:

-- events
local events = game:GetService('ReplicatedStorage'):FindFirstChild('NPCs events')

local setupBomb = events:FindFirstChild('SetupBomb')

-- entries
local entriePoints = workspace:FindFirstChild('Entrances')

local EPNumber = #entriePoints:GetChildren()

-- services
local pathFindingService = game:GetService('PathfindingService')


local function sendToPlace(npc,endPoint)
	local hum = npc:FindFirstChild('Humanoid')
	
	local path:Path
	
	path = pathFindingService:CreatePath()
	
	
	
	path:ComputeAsync(npc.PrimaryPart.Position,endPoint.Position)
	local waypoints = path:GetWaypoints()
	
	-- use the waypoints
	for i, waypoint in pairs(waypoints) do
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			hum.Jump = true
		end
		hum:MoveTo(waypoint.Position)
		hum.MoveToFinished:Wait(2)
	end
	
end




local function enter(npc) -- make an NPC enter the building!
	print('Making '..npc.Name..' enter the place!')
	
	local entryPoint = entriePoints:GetChildren()[math.random(1,EPNumber)]
	print('Entering at '..entryPoint.Name)
	
	sendToPlace(npc,entryPoint)
end

setupBomb.Event:Connect(function(NPC) -- yes this does fire and run.
	task.spawn(enter,NPC)
end)

Anyhow. This only works for the first NPC.
It does not do it for the other two NPC’s.

And yes the Enter function is running.

So I dont know why this is. Is there some kind of thing I have to do to get the SendToPlace function to not just run for the first NPC?
I have no idea!

If you need more context, feel free to ask

1 Like

Based on what you’ve described it sounds like you have a conflict. If you delete the “working” npc does the “non-working” npc start working?

(just curious)

1 Like

It just straight up instantly removes the NPC. So that doesn’t work

1 Like

If it is conflicting it’s just a matter of making the script look at unique object names because if there are objects with the same name it will not know which one you are referencing.

1 Like

Well it wont matter what there name is.
Cause I send them with an event.
So it has the right one

1 Like

After doing some experiments.
When they all spawn next to each other they will not move.
When they all spawn separately only one moves.

1 Like

are the other nps unique or are they all clones of one npc? theres a chance that them may simply be anchored.

1 Like

They are clones of an NPC.
The npc is unanchored

1 Like

The script seems fine, the only thing i can think of is that you might be running the script on the same npc 3 times (ie the script that fires the bindableevent might be wrong)

1 Like

This is where i fire the event for the NPC. As you can see it does do It with different NPC’s every time

local function spawnNPC(npcType) -- spawn enemy
	spawned += 1
	
	if npcType == 'Bomb' then
		print('Spawning a bomb')
		local npc = script:FindFirstChild('BombNPC'):Clone()
		local spawnPoint = spawns:GetChildren()[math.random(1,spawnNumber)]
		
		
		
		npc.Parent = workspace
		npc.PrimaryPart.CFrame = spawnPoint.CFrame -- set the NPC to spawn at the SpawnPoints CFrame
		
		
		
		
		bombEvent:Fire(npc)
		
	else
		print('Spawning a normal')
	end
end
1 Like

I made it print so that every NPC has its own ID.
And when it prints its different so it is moving the right NPC

1 Like

Ok new test.
I made it so it warns the status of the path

Path.Status

And it prints “Enum.PathStatus.NoPath”
How would I make it so it retries or something?

1 Like

Im going to ask else where on the dev forum.
Thanks for the help!

1 Like

Did you ever figure out the issue?

No, sadly it has not been resolved