Pathfinding too laggy

Alright so the problem is with pathfinding an npc , its 2 scripts:

Local script:
i click a button and then gets my mouse and i click somewhere on ground for the npc to walk there, it fires a remote event to server-script

frame.moveto.MouseButton1Click:Connect(function()

movingto = true
frame.moveto.Visible = false
plr.PlayerGui.notify.moving.Visible = true
ms.Button1Down:Connect(function()
	
	if movingto == true then movingto = false
		rem:FireServer(troop,auto,rndm,ms.Hit.Position + Vector3.new(0,troop.HumanoidRootPart.Position.Y,0))
		plr.PlayerGui.notify.moving.Visible = false
	end
end)

end)

Server script:
Receives event from remote and creates pathfinding and everything works fine and the for i,v loop has no wait() and still the pathfinding is laggy (means each pathfind point is generate after few seconds)

if target ~= nil then
ui.Frame.moveto.Visible = false
local path = game:GetService(“PathfindingService”):CreatePath()
path:ComputeAsync(myTorso.Position, target)

		local waypoints = path:GetWaypoints()
	
	for _,waypoint in ipairs(waypoints) do wait()
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			myHuman.Jump = true
		end
		local part = Instance.new("Part")
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Size = Vector3.new(0.6, 0.6, 0.6)
		part.Position = waypoint.Position
		part.Anchored = true
		part.CanCollide = false
		part.Parent = game.Workspace
		
		myHuman:MoveTo(waypoint.Position)
		myHuman.MoveToFinished:Wait()
	end 
	
	
ui.Frame.moveto.Visible = true
end

Please if u know the reason tell me ,if u dont then like this post to make it more visible to others to help me

Thanks for understanding

3 Likes

What does your code look like?

1 Like

Can you provide us with your code?

1 Like

I updated my post, i put the code up there

1 Like

Can you show us an example video of your issue? (If possible)

1 Like

https://i.gyazo.com/d5343d6df3906bf153a8a9fdc5e5961e.mp4
the pathfinding only put 1 point and it takes long to put the other, when the recording stopped , it put 2 other points in time interval idk why

This might be because the NPC isn’t reaching the way-point due to it being in the ground. Did you try to lift the way-points a bit above the ground?

yea, the target path is actually the mouse.Hit.Position+ Vector3.new(0, troop.HumanoidRootPart.Position.Y , 0)

means the target is lifted in y axis as the humanoidrootpart is

Did you get the same result when testing on a Roblox server?

no… can the studio act differently than actual game?

Yea, it might be your pc, it is very unlikely but just to make sure

is it possible if i replace the MoveTo:waypoints.Position to MoveTo:target ??

Does the character stand there for 8 seconds and then continue to the next checkpoint? If so, the character somehow isn’t reaching the destination and the timeout on :MoveTo() times out.

If the Humanoid reaches its goal within 8 seconds, this event will return with reached as true. If the goal is not reached within 8 seconds the Humanoid will stop walking and reached will be false. This timeout can be reset be calling Humanoid:MoveTo again within the timeout period.

not 8 seconds, its like between 1 and 5 sec

I will try to replace MoveTo(waypoints.Position) to MoveTo(target)