[UNSOLVED] Humanoid moving in every case except when called from pathfinding. Help?

Long story short, I am making a new game that contains bots that are supposed to have pathfinding. I am very experienced in making bots, so I decided to make the bot code in a module this time. The bot acts normal, except in the case of pathfinding.

When the pathfinding module is asked to move the character, it doesn’t move. From debugging, everything should work; it returns all the points, attempts to move the humanoid, gets waypoints, etc.

I have been trying for a week now to see what is happening. Can anybody review my pathfinding module to see what could possibly be wrong? I will provide a file AND put the code down below.

Thanks to anybody that can help!

local f = {}

f.FindSpot = function(char,posEnd)
	spawn(function()
		local root,posStart,hum = char.HumanoidRootPart,char.HumanoidRootPart.Position,char.Humanoid
		local posStart = root.Position
		
		local path = game:GetService("PathfindingService"):CreatePath()
		local tag = Instance.new("Vector3Value",char)
		tag.Name = "PrePathfind"
		--tag.Value = posEnd
		local cancel = false
		local waypoints
		local points
		if not pcall(function()
			if char:FindFirstChild("Pathfind") ~= nil then
				char:FindFirstChild("Pathfind"):Destroy()
			end
			tag.Name = "Pathfind"
			path:ComputeAsync(posStart,posEnd,10000)
			waypoints = path:GetWaypoints()
			points = path:GetPointCoordinates()
		end) then
			char.Humanoid:MoveTo(posEnd)
			return
		end
		
		if #points < 2 then
			char.Humanoid:MoveTo(posEnd)
			return
		end
		
		for i,v in pairs(points) do
			hum:MoveTo(v)
			if waypoints[i].Action == Enum.PathWaypointAction.Jump then
				hum.Jump = true
			end
			repeat wait() until (root.Position - v).Magnitude <= 3.5 or tag == nil
			if tag == nil then break end
		end
		
		tag:Destroy()
	end)
end

return f

Pathfinding.lua (1.1 KB)

2 Likes

I think this topic would be more appropriet in #development-support:scripting-support

I moved it to #development-support:scripting-support

1 Like