Replicating NPC position?

So I’m working on a game that heavily relies on the loading / unloading of areas determined by the Client.

To elaborate on this, if a Player were to go from PointA to PointB then A would unload and B would load entirely client side.

I’m trying to find how best to have NPCs replicate their position across the clients so that Players in the same location (i.e. Starbase) sees the same NPC behaving in the same way as opposed to two different clients seeing the NPC at different locations if they were to walk around.

Any suggestions?

1 Like

You could still handle the NPCs on the server side right? Have the NPCs walk around or do whatever they need to do, and the client will only see it once they enter into the area with the NPC.

3 Likes

The issue is the area loading - So although the NPC is on the Server, the map will not. So the NPC will fall through etc

1 Like

Could you anchor the NPCs and unanchor them if necessary when the client enters the area? You could still control the NPC’s CFrame in that case without having them fall through the floor.

2 Likes

You can load a bit of the terrain for all clients on the server side. And if you run into performance issues from loading to much terrain on the serverside you can try to make simpler versions of the 3d models etc on the server side etc.

1 Like

Well. I got the NPC movement replication to work, but I’m not experienced with loading/unloading chunks, though I’m almost getting it work as intended with a basic baseplate chunk load/unload approach.

Here’s a video of a 99% client side NPC movement and animations.

1 Like

Alright. I finally got it work.

Here’s the key notes I have discovered:

  1. You just have to make sure that each NPC generated by each character are standing on top of something, because if one falls off the map then it’s goodbye replication.

Here’s the rbxl file:
NPC Replication and chunks.rbxl (69.4 KB)

2 Likes

Good work!
However from that I can see the Chunk is loading across all Clients?

To summarise my Game will be split into different areas and locations (Planets, Starbases etc.)
The chunk loaded will only be the one the Player requires so any NPCs would fall through?

Yes, that seems to be the case. But I think the solution is to make the server keep track of the NPCs states of each region and when someone approaches the region, you will have to spawn a new NPC and make it immediately match the state the server has.

example:

player1 is in region 3

player1 approaches region 2

server tells player1 that the npc assigned in this region has been doing some stuff

player1 generates a new NPC or parent his NPC for this area to workspace (this is the solution for NPCs falling off unloaded areas)

player1 NPC’s emulate immediately what the npc assigned for that area has done, and what happens from now on accordingly to the latest information provided by other players.

1 Like