RunService Slow (I think)

Background
I created a forum post: NPCs Stuttering while moving - #7 by Judgy_Oreo
Where I was having trouble with NPCs stuttering on traveling to waypoints using the pathfinding function

Because I had a few problems I thought it was all because of one thing which made the post confusing.
I’ve fixed most the problems but I still have the NPC stutter.

Problem
After weeks of trying to solve. I believe its because the RunService.Heartbeat:Wait() is slowing down as the game progresses.

I Added this code to calculate the time it takes to each waypoint.

local Start = tick()
repeat 

local distance = (WaypointPosition - Inhabitant:WaitForChild("HumanoidRootPart").Position).magnitude

RunService.Heartbeat:Wait()

until distance <= 6.2 
warn("ToWaypoint: ".. tostring(tick()-Start))

it starts of at around 0.04-0.06 seconds Which is probably the time it took to move
But then later game it goes to around 1-2 seconds and NPCs start stuttering

I really don’t know why its happening. I have a script that is cloned into each NPC but the Scripts activity is roughly 0.5% (Idk if this is per script or all of them together. Just what it says in script performance)

Lua thread count stays around 500-600 even after the game progresses and I’m 99% sure I close all the threads when they’re not being used in the NPC script

The only thing I can put it down too is memory leaks? but I don’t fully understand it or how to test for it.
So any help with this situation would be much appreciated as its taking me ages to fix

Thanks ~ Anon

1 Like

Can you send a video of this of the NPC stuttering?

1 Like

Video is quite laggy, Not the game

PhoenixwhitefireJudgy_Oreo

1 Like

Does anything happen at this point? Does the game itself start to lag slightly?

1 Like

Nothing noticeable to be honest Just the NPCs

This is the Place if you wanna see it first hand:

https://www.roblox.com/games/6550407980/wip2

If you play for about a min youll see what I mean

Can you uncopylock the place so I can view the place file?

Can’t you use MoveToFinished:Wait() instead to know and wait if the NPC finished moving to each node/waypoint?

If you’re 100% positive you don’t have any loops that aren’t being broken slowly piling up the games activity, I would consider just handling the movement on the client side. You can give network ownership to the player and let them handle movement. It’s a little tricky having 3-6 scripts on the server handling movement that frequently.

1 Like

Just tried, Made no difference.

Thing is, if I can work out why its happening then I can hopefully fix it myself. But I cant work out why its happening,

Timers are constantly low, Client/Server memory is consistent. Ping is not effecting it in anyway. Tried both network ownerships using

InhabitantParts = Inhabitant:GetChildren()
for p = 1,#InhabitantParts do 
	if InhabitantParts[p].ClassName == "MeshPart" or InhabitantParts[p]:IsA('BasePart')then
		InhabitantParts[p]:SetNetworkOwner(nil)
	end
end

Nothings working, There has to be something that the micro profiler is picking up that i cant find because I’m pretty new to it.

Sorry I cant uncopy Lock the place.

I’ve tried this as well. Im starting to think it isn’t because of the wait time() and rather the replication from client to server. but it might be something else i don’t know :frowning: