Hi, all. I have a script in a Humanoid that is supposed to find a random player and use Roblox's pathfinding service to maneuver its way around walls to get to the player.
But the Humanoid doesn't go anywhere, and there are no errors in the output.
Here's the script inside the Humanoid:
local root = script.Parent.Parent.HumanoidRootPart -- Get the zombie's HumanoidRootPart
function moveToPlayer() -- Declare the function
local players = game.Players:GetPlayers() -- Get a list of players
for _, each in ipairs(game.Players:GetPlayers()) do -- Find a random player
local char = each:FindFirstChild("Character") -- Get player's character...
if char then -- ...and check if it exists
local human = char.Humanoid -- Get the char's humanoid
if human.Health > 0 then -- Check if the humanoid still alive
local pRoot = human.Parent.HumanoidRootPart -- Get the character's HumanoidRootPart
local path = game:GetService("PathfindingService"):ComputeRawPathAsync(root.Position, pRoot.Position, 500) -- Compute a path
local points = path:GetCoordinates() -- Get a list of the coordinates
for i = 1, #points do
script.Parent:MoveTo(points[i]) -- Make the zombie move along the points
end
end
end
end
end
while wait() do
moveToPlayer()
end
Please help me. I'll give you a free, imaginary, figurative, nonexistent cookie if you do!

6 comments
Does MoveTo automatically yield, because if not then you should add a wait
Also, try making the while wait() do loop a bit less frequent
Why do you comment on everything it's a nuisance to read through code when half of it is a comment
@frosty, Because I'm desperate to fix this so I commented on everything to help me figure it out; I don't do this regularly. Also, if you're just here to criticize my commenting and not help me, I politely ask you to leave.
Also @Nexa, I tried both of those but nothing helped. :(
Criticism is what helps you get better snowflake