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