AI isn't moving but the jumpscare plays meaning the script runs with no errors

As the title suggests, the character isn’t moving but the jumpscare plays perfectly. There is no output error.

local pfs = game:GetService("PathfindingService")
local pathparams = {
	["AgentHeight"] = 6.5,
	["AgentRadius"] = 5,
	["AgentCanJump"] = false
}
local waypoints = {}
local goal = workspace.endpart
local waypointindex = 1
script.Parent.PrimaryPart:SetNetworkOwner(nil)
local torso = script.Parent:WaitForChild("Torso")
local humanoid = script.Parent:WaitForChild("Humanoid")
local root = script.Parent:WaitForChild("HumanoidRootPart")
local anim = script.Parent.JumpscareAnimation
local animation = humanoid:LoadAnimation(anim)
root.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		script.Parent:WaitForChild("Jumpscare"):Play()
		animation:Play()
		root.CanTouch = false
		root.Anchored = true
		plr:WaitForChild("Humanoid").WalkSpeed = 0
	 	plr.PlayerScripts:WaitForChild("RunningScript"):Destroy()
	end
end)
local path
local function Walk()
path = pfs:CreatePath(pathparams)
	path:ComputeAsync(torso.Position, workspace.endpart.Position)
	if path.Status == Enum.PathStatus.Success then
		local waypoints = path:GetWaypoints()
		waypointindex = 1
			humanoid:MoveTo(waypoints[waypointindex].Position)
	end
	path.Blocked:Connect(function(blockedwaypointindex)
		if blockedwaypointindex > waypointindex then
			Walk()
		end
	end)
end
Walk()

If it is not moving that means there is something wrong with the moving function here.

Try checking if the path is successfull by printing it out, then visualizing the way points of the path to see the travel path.

Also it seems to only travel to the first waypoint, usually a path can have many waypoints so you should look into that further.

1 Like

Looking really didn’t help me at all. The official Roblox documentation for the blocked path won’t even work because they forgot to assign a variable. If you could explain to me i would be really thankful.

Sure I will explain,

Your code does not match with the documentation tutorial.

I do not see waypoint += and a MoveToFinished connection in your code which plays an integral role in allowing the pathfinding to work and move on to the next path waypoint.

		if not reachedConnection then
			reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
				if reached and nextWaypointIndex < #waypoints then
					-- Increase waypoint index and move to next waypoint
					nextWaypointIndex += 1
					humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
				else
					reachedConnection:Disconnect()
					blockedConnection:Disconnect()
				end
			end)
		end

If you are having difficulties consider using a SimplePath module which does the job from my experience and others. This also uses :MoveToFinished function which you are missing from your code to make the humanoid go to the next waypoint.

And also a tutorial link:

Don’t worry though that is just the programming research process of researching resources that either work or don’t work. However please do look into the new documentation tutorial and other people’s tutorial and don’t give up from there.

1 Like

My code is entirely based off devking’s tutorial, and i tried using the Roblox documentation but i just didn’t understand so i used another post as refrence and it seemed alright.

Also i forgot to say, I’m currently just using a part but i want to make it follow the player’s humanoidrootpart (as it’s a scripted chase) so the monster doesn’t lose the player. And i just realized that’s just 1 waypoint.