Default FPS system not damaging NPCs

I’m using Roblox’s default FPS system, and when trying to damage an NPC with an AI script in it, it won’t take damage.
Script is here:

char = script.Parent
local function MoveToFinished(humanoid,position)
	local Timeout = true
	local event = humanoid.MoveToFinished:Connect(function(successful) if not successful then humanoid:MoveTo(position) return end if successful then Timeout=false end end)
	repeat task.wait() until Timeout==false
	event:Disconnect()
	return
end
function CharMove(char, map)
	local targetreached = true
	local humanoid = char:WaitForChild("Humanoid")
	local waypoints = map.PathFolderRight

	for waypoint=1, #waypoints:GetChildren() do
		humanoid:MoveTo(waypoints[waypoint].Position)
		MoveToFinished(humanoid,waypoints[waypoint].Position)
	end

	humanoid.Health = 0

--	map.Base.Humanoid:TakeDamage(humanoid.Health)
end
CharMove(script.Parent,game.Workspace)

I literally have no idea why it won’t damage an NPC with AI in it

Still haven’t figured this out. No clue why an AI script stops it from working

why have a seperate function for MoveToFinished?

you know you can just do humanoid.MoveToFinished:Wait() right?

also are you sure the for loop ever stops running? maybe it’s something to do with that strange ahh repeat loop

imma be fr dawg i stole the code literally have no idea

im gonna try to see if the for loop stops running but idk how thatd stop it from taking damage

dawg imma also be fr your code cursed af

passing workspace as a function parameter is absolutely devious

both loops do stop running at some point so idk