So i did a tutorial on Youtube, With a ai and now there is a problem. When you put the ai into a obby, It jumps but it can jump infinitely. I dont know why this does happen, But i tried to fix it. What i did is whenthe humanoid is jumping, Wait for it to fall down and THEN it may jump another time.But what happened was that the ai isn't moving or jumping at all. Maybe some of you can fix this?

-- script is placed inside a movable NPC model
 
-- get pathfinding service
local pathfindingService = game:GetService("PathfindingService")
 
-- Variables for NPC humanoid, torso, and destination
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local destination = game.Workspace.Destination.Position
 
-- create path object
local path = pathfindingService:CreatePath()
 
-- compute a path
path:ComputeAsync(body.Position, destination)
 
-- get the waypoints table
local waypoints = path:GetWaypoints()
 
-- iterate through all waypoints, and jump when necessary
for k, waypoint in pairs(waypoints) do
	if Enum.HumanoidStateType.Freefall == nil then
      	humanoid:MoveTo(waypoint.Position)
    end
    -- change humanoid state to jump if necessary
    if waypoint.Action == Enum.PathWaypointAction.Jump and Enum.HumanoidStateType.Freefall == nil then
        humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    end
   
    humanoid.MoveToFinished:Wait()
end

Please give a deep explanation and why, And don't copy the script from another answer. Ty! (: