The zombie just stays still no matter what changes i make to the script
local pathfindingService = game:GetService("PathfindingService")
local zombie = script.Parent
local HumanoidRootPart = zombie:WaitForChild("HumanoidRootPart")
local Humanoid = zombie:WaitForChild("Humanoid")
local Players = game:GetService("Players")
for i, v in pairs(zombie:GetChildren()) do
v.Anchored = false
end
function getNearestCharacterToPart(part)
local currentPlayer = nil
local distanceToNearest = math.huge
for _, player in Players:GetPlayers() do
local char = player.Character
local hrp = if char then char:FindFirstChild("HumanoidRootPart") else nil
if hrp then
local dist = (hrp.Position - part.Position).Magnitude
if dist < distanceToNearest then
currentPlayer = player
distanceToNearest = dist
end
end
end
return currentPlayer
end
local nearestPlayer = getNearestCharacterToPart(HumanoidRootPart)
game:GetService("RunService").Heartbeat:Connect(function()
if nearestPlayer then
local path = pathfindingService:CreatePath()
local success, errorMessage = pcall(function()
path:ComputeAsync(HumanoidRootPart.Position, nearestPlayer.Character.PrimaryPart.Position)
end)
if success then
local waypoints = path:GetWaypoints()
for i, v in pairs(waypoints) do
Humanoid:MoveTo(v.Position)
end
end
if not success then
warn(errorMessage)
end
end
Humanoid.MoveToFinished:Wait()
end)