HI devforum, Im currently making a tool which when used, summons a bomb which pathfinds to the nearest player. However, immidietley upon summon it pathfinds to the summoner. How would i make it so the pathfinding ignores the summoner
script
local rep = game.ReplicatedStorage
local EWeapons = rep.ReplicatedCommon.WeaponEvents
local Weapons = rep.Weapons
game.Players.PlayerAdded:Connect(function(player)
local function summon()
local Bomb = Weapons.TripSwitchBomb:Clone()
local CF = player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0.5, -4)
Bomb.Parent = workspace
Bomb.HumanoidRootPart.CFrame = CF
--Services--
local RunService = game:GetService('RunService')
local PathfindingService = game:GetService('PathfindingService')
--Variable--
local hum = Bomb.Humanoid
local humrp = Bomb.HumanoidRootPart
--Pathfinding
Bomb.PrimaryPart:SetNetworkOwner(nil)
local destination = workspace.wp.Position
local function findTarget()
local players = game.Players:GetPlayers()
local MaxDistance = 200
local nearestTarget
for i,v in pairs(players) do
if (v.Character) then
local target = v.Character
local distance = (humrp.Position - target.HumanoidRootPart.Position).Magnitude
if (distance < MaxDistance) then
nearestTarget = target
MaxDistance = distance
end
end
end
return nearestTarget
end
local function agro(target)
local distance = (humrp.Position - target.HumanoidRootPart.Position).Magnitude
if (distance > 8) then
hum:MoveTo(target.HumanoidRootPart.Position)
else
target.Humanoid.Health = 0
local Explosion = Instance.new("Explosion")
Explosion.Parent = workspace
Explosion.ExplosionType = Enum.ExplosionType.NoCraters
Explosion.BlastRadius = 3
Explosion.DestroyJointRadiusPercent = 0
Explosion.Position = Bomb.HumanoidRootPart.Position
Bomb:Destroy()
end
end
local function createPath(destination)
local path = PathfindingService:CreatePath()
path:ComputeAsync(humrp.Position, destination)
return path
end
local function walkTo(destination)
local path = createPath(destination)
local waypoints = path:GetWaypoints()
for i,v in pairs(waypoints) do
local target = findTarget()
if (target) then
agro(target)
break
end
hum:MoveTo(v.Position)
hum.MoveToFinished:Wait()
end
end
while task.wait(0.5) do
walkTo(destination)
end
end
game.ReplicatedStorage.ReplicatedCommon.WeaponEvents.summonBomb.OnServerEvent:Connect(function(player)
summon()
end)
end)