Why Isn't the pathfinding script for a zombie not working?
So I made a script that makes a zombie follow the player, but also have pathfinding (Meaning It can find the player In mazes,behind walls,etc. but It appears to not follow the player:
01 | local NPC = script.Parent |
02 | local PathfindingService = game:GetService( 'PathfindingService' ) |
03 | local Players = game:GetService( "Players" ) |
06 | game.Players.PlayerAdded:Connect( function (client) |
10 | repeat wait() until player ~ = nil |
12 | local path = PathfindingService:CreatePath() |
14 | path:ComputeAsync(NPC.Torso.Position, player.Character.PrimaryPart.Position) |
16 | if path.Status = = Enum.PathStatus.Success then |
17 | local Positions = path:GetWaypoints() |
19 | for i,v in pairs (Positions) do |
20 | local ball = Instance.new( "Part" , workspace) |
22 | ball.Position = v.Position |
24 | ball.CanCollide = false |
25 | ball.Size = Vector 3. new( 4 , 4 , 4 ) |
26 | ball.Transparency = 0.5 |
27 | ball.Shape = Enum.PartType.Ball |
29 | NPC.Humanoid:MoveTo(player.PrimaryPart.Position) |
30 | NPC.Humanoid.MoveToFinished:Wait( 2 ) |