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 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.
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)
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