Hi I am making a monster that chase a player but it isn’t working now but it was work before. Here is code
local PathfindingService = game:GetService("PathfindingService")
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Zombie = script.Parent
local Humanoid = Zombie.Humanoid
local HumanoidRootPart = Zombie.HumanoidRootPart
local function findClosestPlayer()
local closestPlayer = nil
local closestDistance = 120
for _, player in ipairs(Players:GetPlayers()) do
local character = player.Character
if character and character:FindFirstChild("Torso") then
local distance = (HumanoidRootPart.Position - character.Head.Position).magnitude
if distance < closestDistance then
closestPlayer = character
closestDistance = distance
end
end
end
return closestPlayer
end
local function followPath(destination)
local path = PathfindingService:CreatePath()
path:ComputeAsync(HumanoidRootPart.Position, destination)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
HumanoidRootPart:SetNetworkOwner(nil)
for i, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid:MoveTo(waypoint.Position)
end
end
end
local function updatePath()
local closestPlayer = findClosestPlayer()
if closestPlayer then
followPath(closestPlayer.Head.Position)
end
end
RunService.Heartbeat:Connect(updatePath)
I try a lot of things but nothing worked so I’m glad if somebody helped me