Mass despawn of NPCS happening in game for no apparent reason

Hello, I’m here to talk about an issue that I’ve been having in my game where ALL NPC’s would disappear all at once at seemingly random times. I do not know the cause of the issue at all and there appears to be NO errors in the console what so ever. No destroy function is ever present unless the NPC has been killed, and there is nothing that causes all NPCS to be killed all at the same time. All NPCS are parented into a folder in workspace called “Mobs” and there’s no script or line of code that calls for a “ClearAllChildren:()” in the folder where the NPCS are parented into.

Some main things that I inferred that may be the cause is:
NPCS use body gyro as a rotation to face towards the player.

During a really early playtest, spawning an NPC nearby other NPCS would cause all NPCS to despawn for some reason.

If anybody else has had a similar issue please let me know if there’s a fix, all would be greatly appreciated.

1 Like

Okay, let’s try taking out “potential issues” – temporarily disable the body gyro.

Could you put prints on all :Destroy() lines? See if they all trigger whenever they all disappear. Could you also use Ctrl + Shift + R to look for all the other lines that might lead to them destroying the NPCs (and either remove them or add prints to them aswell):

Some questions:
Do the NPCs just straight up disappear from sight?
Are you using a free model NPC or a custom made one?
Are you aware of any viruses that are in/used to be in your game?
Are the NPCs being deleted on the client only or on the server aswell?
Also what objects/code are interacting with the NPC physically? Its possible that a value is set really high and the NPCs gets launched/fall through the baseplate. Or their position is set too low into the void.

Try disabling streaming enabled? I have heard things like this before and sometimes that helps

1 Like

its probably because CFrame.lookat is returning nan, its a known issue if where the CFrame.lookat points are little similar they return nan

a fix can be seen here CFrame(X,X) producing NaNs - #6 by Evercyan

3 Likes

I found the issue, turns out when the player is extremely close up to the NPC it sometimes causes the bodygyro to just delete the NPC and everything within it’s folder. I’ve managed to fix this issue by making the NPC’s bodygyro rotate towards slightly offset from the player.

1 Like

Oooo good catch dude, I totally missed that possibility.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.