PathFindService will stuck in part

Hi.

  1. What do you want to achieve?
  • Make a Character that follows the player ( start in the script ) in the Module Script.
  1. What is the issue?
  • When I run this ( on floppa that has Humanoid and HumanoidRootPart ) floppa will be stuck in part and won’t move even though I’m next to floppa.
  1. What solutions have you tried so far?
  • I did a search on the Roblox Dev forum but I didn’t find anything that did help.

Module Script:

function module.FollowPlayerAI(start, radius)
	while true do
		local player = module.FindNearestPlayer(start, radius) -- (finds the nearest player that has Humanoid, HumanoidRootPart, and Head) return Player Character (Model)
		local humanoid = module.CheckHumanoid(start) -- (check if start has humanoid and HumanoidRootPart or if start's Parent has humanoid and HumanoidRootPart) return Humanoid

		if not humanoid or not player then return end 

		local path, Waypoints = module.MakePath(start, player) -- make a path and returns Path and Waypoints
		for i, waypoint in pairs(Waypoints) do
			humanoid:MoveTo(waypoint.Position)
			
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
		end
        wait()
	end
end

Script:

local module = require(game.ReplicatedStorage.MainModule)
module.FollowPlayerAI(script.Parent, nil) -- if the radius is nil then the radius is math.huge

Not sure on this but isn’t the script supposed to throw a “script exhausted” error since you don’t have any delays?

Oh, I forgot to add wait() but I have it in module script

Add a humanoid.MoveToFinished:Wait, or use something like SimplePath to handle all this for you.

for i, waypoint in pairs(Waypoints) do
	humanoid:MoveTo(waypoint.Position)
	
	if waypoint.Action == Enum.PathWaypointAction.Jump then
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
	
	humanoid.MoveToFinished:Wait()
end
1 Like