I have a problem with my zombie pathfinding. Again. It doesn’t actually pathfind, and just runs into walls.
local function spawnArm(player)
local clone = arm:Clone()
clone.Parent = folder
clone.PrimaryPart.Position = positions[math.random(1, #positions)].Position + Vector3.new(0, 1, 0)
clone.Hitbox.CFrame = clone.PrimaryPart.CFrame
clone.PrimaryPart.Appear:Play()
task.spawn(function()
wait(15)
if clone.Parent ~= nil then
print("Zombie has escaped!")
local savedArmCFrame = clone.PrimaryPart.CFrame
clone:Destroy()
if zombie:FindFirstChild("HumanoidRootPart") and zombie:FindFirstChildOfClass("Humanoid") then
local char = player.Character or player.CharacterAdded:Wait()
local zombieClone = zombie:Clone()
zombieClone.Parent = folder
zombieClone.HumanoidRootPart.CFrame = savedArmCFrame
zombieClone.HumanoidRootPart:SetNetworkOwner(nil)
--[[zombieClone.HumanoidRootPart.Touched:Connect(function(hit)
local hitHum = hit.Parent:FindFirstChild("Humanoid")
local isPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if isPlayer and hitHum then
removeZombies()
print("Zombie touched! Stopping game..")
end
end)]]--
local path = PFS:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = false,
AgentCanClimb = false,
WaypointSpacing = 3
})
while char do
if zombieClone:FindFirstChild("HumanoidRootPart") and (char ~= nil) and zombie:FindFirstChildOfClass("Humanoid") then
path:ComputeAsync(zombieClone.HumanoidRootPart.Position, char.HumanoidRootPart.Position)
local waypoints = path:GetWaypoints()
for i, point in pairs(waypoints) do
zombieClone.Humanoid:MoveTo(point.Position)
end
end
wait()
end
end
end
end)
end
Do i make it compute a new path when it fails?