Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pathfinding script won't work when the zombie model Is cloned (?)

Asked by 2 years ago

Anyway, so there Is a problem with my zombie model, as the title says, the pathfinding doesn't appear to work when the zombie model (A R6 model) was cloned In say, replicated storage, It does work when not being cloned, I was wondering why thats happening

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

Answer this question