So I have some NPCs which walk around my map. But for some reason the walk animation stutteres ingame but not in studio
This is the code that controls the NPCs movement
local function moveNPCToWaypoints(npcPart, npcPathFolder)
local waypoints = npcPathFolder:GetChildren()
local nextWayPointIndex
local reachedConnection
local blockedConnection
local currentWaypointIndex = 1
local Walkspeed = npcPart:GetAttribute("Walkspeed")
local humanoid = npcPart:FindFirstChild("Humanoid")
humanoid.WalkSpeed = Walkspeed
npcPart.PrimaryPart:SetNetworkOwner(nil)
local function getPath(destination)
local path = Pathfinding:CreatePath({
AgentHeight = 3;
AgentRadius = 2.25;
AgentCanJump = false;
AgentCanClimb = false;
Consts = {
Waiter = 100;
DangerZoner = math.huge
}
})
if npcPart ~= nil and npcPart:FindFirstChild("HumanoidRootPart") then
path:ComputeAsync(npcPart.HumanoidRootPart.Position, destination.Position)
end
return path
end
local function walkTo(destination)
local path = getPath(destination)
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(path:GetWaypoints()) do
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
else
if npcPart ~= nil and npcPart:FindFirstChild("HumanoidRootPart") then
humanoid:MoveTo(destination.Position - (npcPart.HumanoidRootPart.CFrame.LookVector * 10))
end
end
end
local function Patrol()
local currentWaypoint = waypoints[currentWaypointIndex]
walkTo(currentWaypoint)
if currentWaypoint:FindFirstChild("WaitTime") then
local WaitTimeValue = currentWaypoint.WaitTime.Value
wait(WaitTimeValue)
end
currentWaypointIndex = currentWaypointIndex + 1
if currentWaypointIndex > #waypoints then
currentWaypointIndex = 1 -- Reset back to the first waypoint
end
end
while wait(.01) do
Patrol()
end
end
And the NPCs animation is being controlled by a slightly modified version of the default animation handler