NPC movement stuttering

I’ve been having this one little issue with my NPCs, the longer the game is up, the more the NPCs stutter in their movement. I’ve gone through ~20 posts here on the DevForum, and they all said the same.

“Set the primary part network ownership to the server.”

This is precisely what I’ve tried, and it doesn’t work. Here’s my code which does it.

for _, part in pairs(character:GetChildren()) do
    if part:IsA("BasePart") then
        PhysicsService:SetPartCollisionGroup(part, "npcs")
        part:SetNetworkOwner(nil)
    end
end

The same thing still happens, I’ve tried countless stuff, but nothing has changed.
Any ideas?

3 Likes

Have you tried adding a print statement under the If to ensure the script is actually running the command part:SetNetworkOwner()?

I really hope someone with a good understanding of Lua. Can help HedTB, I’ve known him for a while and he’s a really ambitious roblox developer pushing his limits!
Any replies or help is much appreciated.

Yeah, I tried that. I also tried printing it inside of the movement, and it stayed as nil.

What is the memory usage of the game like over time?

Do you have anything welded to the NPCs?

Hmm, it seems like I have a memory leak? Not sure, also keep in mind the memory usage is very high as I’m play-testing inside Studio.

After doing a little bit of digging I found this. Try giving this a shot and if it prints and error if you could tell me what It is we can probably figure it out.

local success, errorReason = Character:CanSetNetworkOwnership()
if success then
	Character:SetNetworkOwner(networkOwner)
else
	-- Sometimes this can fail, so throw an error to prevent
	-- ... mixed networkownership in the 'model'
	error(errorReason)
end
1 Like

Yeah, I have a hitbox part welded to the NPCs. Could this be an issue?

I only ask because i had issues with my NPCs and i read that if your script welds something to the NPC to also set network ownership both before and after the weld.

6 Likes

Oh wait, I’m actually welding it after setting the network ownership… :man_facepalming:
Let me change that and see if it changes anything, if so, I’ll set your post as the solution.

Update: Wow, that little hitbox caused that much damage… Thanks so much for the help!

3 Likes

Yeah before i joined the forum i spent a long time trying to fix my NPC issues, and that one was a big one.

1 Like