Help with pathfinding script

i was coding a script where a dummy chases after a part, it was working fine yesterday but now it broke somehow, now it just moves directly to the part instead of pathfinding to it

pathfinding script:

local target = workspace:WaitForChild("target")

local pathfindingservice = game:GetService("PathfindingService")

local root = script.Parent:WaitForChild("HumanoidRootPart")
local humanoid = script.Parent:WaitForChild("Humanoid")

local path

local waypoints
local waypointnumber = 1


local updatepath = coroutine.create(function()
	while true do
		wait(1)
		if path ~= nil then
			path:Destroy()
		end
		path = pathfindingservice:CreatePath()
		path:ComputeAsync(root.Position, target.Position)
		
		if path.Status == Enum.PathStatus.Success then
			waypoints = path:GetWaypoints()
			waypointnumber = 1
		else
			print("error.")
		end
	end
end)

coroutine.resume(updatepath)


repeat wait() until waypoints ~= nil

while true do
	if waypointnumber <= #waypoints then
		local waypoint = waypoints[waypointnumber]
		
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		else
			humanoid:MoveTo(waypoint.Position)
		end
		waypointnumber = waypointnumber + 1

		humanoid.MoveToFinished:Connect(wait)
	else
		wait()
	end
end
local pfs = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local root = script.Parent:WaitForChild("HumanoidRootPart")
local path = pfs:CreatePath()
path:ComputeAsync(root.Position, game.Workspace.Ending.Position)
-- change “Ending” to what ever you want the ending part to be
local waypoints = path:GetWaypoints()
for i, waypoint in pairs(waypoints) do
print("Working")
local part = Instance.new("Part")
-- here you can mess around
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.5,0.5,0.5)
part.Position = waypoint.Position + Vector3.new(0,1.5,0)
part.Anchored = true
part.CanCollide = false
part.Parent = workspace.WayPoints -- or you can put in anywhere you like but i recommend to put it in a folder
-- dont change anything bellow this line
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait()
end

-- if this script does not work then try to anchor and unanchor the npc

i tried it and the waypoints are working correctly, nothing is going wrong
however the same issue is still happening

the npc is anchored and unanchored, i already told you it was working before and moving, it just moves directly to the part’s position and not following the waypoints

i somehow found a working answer, for some reason the answer to the error was changing the:

humanoid.MoveToFinished:Connect(wait)

to

humanoid.MoveToFinished:Connect(wait())

for some reason that works

edit nvm lol