NPC's behave differently on the Server than Locally

Hello,

Currently, I have a NPC’s system, they spawn, navigate to specific points, and so on, currently, when i test locally in studio, they run correctly and with no issues, but, if i publish the game, and test the game on roblox, the NPC’s behave weird, their walk is jittery, and they walk to random points that they are not suppose to. breaking the whole system.

I havent tried any Solutions as of now because this is the first time im faced with such issue and dont know where to begin solving it. could it be a roblox server issue?

If you have faced and solved such issue before, please leave you fix down below, thank you for your valuable time!

Hello!

Something to test would be NetworkOwnership.

Whenever an NPC gets near a player, the server tries to transfer ownership to the player.

In essence, this means the physics calculations go to the player, and this messes really heavily with pathfinding and MoveTo events.

Please let us know if you are using Pathfinding, MoveTo events, etc…

For now, you can try placing a script in the NPC with the following code:

local root = script.Parent
root:SetNetworkOwnership(nil)

Providing of video of the jittering would also be helpful!

2 Likes

Hey, thanks for the quick response,

For the pathfinding im using the SimplePath module with the MoveTo event.
and in my pathing module im already setting the
SetNetworkOwner to nil. so that shouldnt be the issue.

pcall(function()
	self._agent.PrimaryPart:SetNetworkOwner(nil)
end)

Also, here are 2 videos, 1 in Studio with no issues, and 1 when the same game is published and tested.
Studio:


In game:

1 Like

wow…

alright so basically the npc are avoiding entrace which can be a problem with the pathfinding service.

could you provide:

Which type of script are you using(local or server)
Are you firing too much MoveTo functions at the same time? (for example i saw when they enter the store they get out… MAYBE the function is overlapping the rig and making it go wonky)
Do you use to move to a certain part or position for example like MoveTo (part) or move to Position

1 Like

SimplePath already has some debug visualization built in that you can turn on. Just look in the code and see where the createVisualWaypoints() function is called, and satisfy the conditions (in latest, it’s just a matter of adding self.Visualize = true to the class new function, or just removing this check temporarily.

Studio has debug visualization for the navmesh built in, but unfortunately, your bug is only happening in the live environment, so there might not be any clues from this. But maybe you’ll see something? Worth toggling it on just to see what your navmesh looks like. The weird thing in the second video is how the characters all path to the same wrong point, both when going into the store and leaving. It’s almost like the navmesh has a glitch on the live server, like the triangulation is different and it’s adding an extra waypoint, or pathing around some obstacle or hole in the terrain that isn’t actually there. Is the ground in front of the store just a single block Part, with no seams or custom meshes or Unions, or is it custom SmoothTerrain?

So all my NPC logic runs on the server, via module scripts.
and for the MoveTo its driven by the simplepath, it uses 1 MoveTo per waypoint.
and im using the MoveTo part, so NPC’s move to specific parts i place.
Also to address your concern of why they enter the store and return, its just how i have it set up currently, so its a part of the game loop.

Yes, so the Floor infront of the store is just a single meshpart with a texture, there is 0 reason for the NPC’s to be going to that position, its very weird.

Have you enabled either the navmash debug view or convex decomposition view? Navmesh generation with regular block Parts is generally stable, but things can be weird with MeshParts and SmoothTerrain, because Roblox aggressively LoDs these in some cases, and unlike regular Parts, the collision geometry and visual (render) geometry are not the same mesh! It’s entirely possible for a MeshPart to look correct, but to have bad collision geometry that affects pathing. Like if there is even a tiny bump, hole, or some degenerate geometry in the mesh or in the generated collision mesh, it could cause PathfindingService to path around the defect. But any such defect is totally invisible unless you enable the debug visualizations. Studio and Server working with different collision fidelity (different LoD levels of the mesh) could possibly explain the discrepancy.

I appreciate your time, i managed to get the Weird animation jitter fixed correctly.

i tried every thing you suggested for the pathfinding but nothing worked, so i ended up hard coding the movement out side of the store, and enabling the pathfinding only in the store. which seems to have fixed the issue completely.