Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How come my pathfinding npc script is so laggy and stuttering?

Asked by 2 years ago
Edited 2 years ago

so ive been working on this all day and basically my npc stutters or lags when it moves. it like freezes for a half a second pretty often

its supposed to follow the player even when they move

local function getpathfindingpath(entity, nearestplr)
    local entityPath = pathFindingService:FindPathAsync(entity.PrimaryPart.Position, nearestplr.PrimaryPart.Position)
    local waypoints = entityPath:GetWaypoints()
    return waypoints[2]
end

wait(5)
local function getwaypoints(v)
    local nearestplr = game.Players:WaitForChild('thenormalelevator3').Character  
    local waypoint = getpathfindingpath(v, nearestplr)
    return {waypoint, nearestplr}
end
for q,w in pairs(entity:GetChildren()) do
    if w:IsA('BasePart') then
        w:SetNetworkOwner(nil)
    end
end

runservice.Heartbeat:Connect(function()
local waypoints = getwaypoints(entity)
    local v = waypoints[1]
    if v ~= nil then
        local pos = v.Position
        entity.Humanoid:MoveTo(pos)

    end

    end)

here's my code

0
Yeah the roblox Pathfinding sucks. I recommend using CreatePath instead of FindPathAsync because it's deprecated. T3_MasterGamer 2189 — 2y
0
hm i was using createpath before with the same results but ill probably move back over thenormalelevator3 0 — 2y
0
add a few wait() here and there it works sometimes but idk if itll be helpful really cause that removes a bit of lag blackcatbabydragon 12 — 2y

Answer this question