Hi! i have an error but i don’t know how to fix it.
The problem is when i jump to void NPC stops chasing me.
Here is the output
Script:
local zombie = script.Parent
local humanoid = zombie.Humanoid
local function findTarget()
local players = game.Players:GetPlayers()
local maxDistance = 530
local nearestTarget
for index, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (zombie.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget
end
while wait(0.01) do
findTarget()
local target = findTarget()
if target and target.Humanoid.Health > 0 then
humanoid:MoveTo(target.HumanoidRootPart.Position)
end
end
This my first Topic, i may be bad at creating topics.