So What I mean Is that, I want to modify this script so when you summon a NPC It will protect you by following the other players, damaging them?
Oh and also a problem with the script Is that If being cloned lets say, replicatedstorage then, the pathfinding script stops working
script:
local NPC = script.Parent
local PathFindingService = game:GetService("PathfindingService")
local player
game.Players.PlayerAdded:Connect(function(client)
player = client
end)
repeat wait() until player ~= nil
while wait() do
local Path = PathFindingService:CreatePath()
Path:ComputeAsync(NPC.Torso.Position, player.Character.PrimaryPart.Position)
if Path.Status == Enum.PathStatus.Success then
local Waypoints = Path:GetWaypoints()
for i,v in pairs(Waypoints) do
local Position = Instance.new("Part", workspace)
Position.Position = v.Position
Position.Anchored = true
Position.CanCollide = false
Position.Size = Vector3.new(1,1,1)
NPC.Humanoid:MoveTo(Position.Position)
NPC.Humanoid.MoveToFinished:Wait()
Position:Destroy()
end
end
end

2 comments
Okay, thanks for the Information! But as you stated on the PlayerAdded, what line of code should I replace It?
It would be whatever portion of your code deals damage.