Problems with pathfinding

I wanted to make a npc that does a obby and it worked if i runned the game but if i played the game it didnt work anymore

it worked at the beginning:
https://streamable.com/ahdbqh

Till here:
https://streamable.com/46z0lw

my script:

local pathfinding = game:GetService("PathfindingService")

local hum = script.Parent.npc.Humanoid
local torso = script.Parent.npc.PrimaryPart

local path = pathfinding:CreatePath()
path:ComputeAsync(torso.Position,script.parent.End.Position)
local waypoints = path:GetWaypoints()

function obby()
if path.Status == Enum.PathStatus.Success then
		for i, waypoint in pairs(waypoints) do
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				hum:ChangeState(Enum.HumanoidStateType.Jumping)
			end
			hum:MoveTo(waypoint.Position)
			hum.MoveToFinished:Wait(.5)
		end
	end
end

while wait(1) do
	obby()
end
1 Like