Client rendered NPCs not being in sync with other clients

So I have a NPC zombie system that creates configs on the server, with every info the zombie will have, e.g: Health, Target’s position, etc. When the configs are created, a remote event then signals to all clients to create those zombies in eachother’s POV.
image

The zombie’s pathfinding is done on the client, anything related to it’s final destination or where it is is stored in the config’s attributes, essentially:
Server handles where the NPC is and should go to, while client will handle the visuals and pathfinding.

The pathfinding is handled with a single local script, using collection service and as the collection service’s parameter: client models that have spawned.
If pathfinding failed or the zombie didn’t reach the destination because of an error, it’ll just teleport to the destination or it’s next waypoint respectively.

Unfortunately, when a new player joins, it doesn’t render the first player’s zombies that were spawned, to counter this, I made a remote event fire the table of zombies that are alive when a new player joins, it works well but sometimes there are still “Ghost” zombies that don’t appear on some player’s screens.

The only problem I see with this is that I’m firing remote events from the client to update the zombie’s position so that players can deal damage to the zombies
(because the zombies are client sided, the gun system checks if the zombie hit from the client is legitimate through a distance check using the NPC’s config position)

So i think that because multiple clients are sending position data, the NPC gets confused with the pathfinding but I don’t know how I’ll be able to validate gun shots or make safe and exploit-free attacks for special zombies, without the zombie’s position

Client Script for creating zombies normally:

Client script for new player’s zombie spawn:

Server script for new players joining:

In summary, I want to know how I can make sure all zombies on each client know where they are supposed to be standing, and prevent ‘ghost’ zombies from happening

Reasons why I’m opting for this method over server NPCs:

  • I can spawn 300+ zombies with minimal lag
  • It gives me more freedom to do effects and more detailed models
2 Likes

Why are you making own life harder?
Also :GetAttributes() exists
Server doesn’t need rendering anything.
Just keep NPCs on server since you are making pathfinding there anyway

I want to spam hordes , if I use the server for this, it’ll lag a lot
The pathfinding is being done on the client

Create a class of Horde, code it and spawn it in game… oh wait roblox doesnt allow you to create classes. So you have to do a wobbly workaround by using metatables and then spawn the model into the game from the code

So create the zombie’s class on server and replicate it to the clients?

No, make it all in server replicating to every client is already not a good idea.

From what I learnt and saw, with this method I can spawn up to 300+ zombies with no frame drops and keep the server load clear

It’s also the method used in tower defense/strategy games to render lots of enemies with minimal lag:

The only difference being that I’m using no parts on the server to represent the zombies, only configs

1 Like

This is a good method, I’ve been using it for my own horde system

Only video I have atm, but there isnt any TRUE way to have the most accurate representation/replication across all clients, since all clients will load the zombies at different speeds

For a truly smooth experience with about 250-300 overseers, I just entrust much of the logic to the client and only do a few server checks.

I dont know what you could REALLY do, since Im still in the process of ironing everything out.

You could try using the server to predict where the NPC would realistically be (using only time and initial position and its final position), but this is a lot of prediction math so who knows?

You could create a server part for every zombie/unit and the client will trust that over just receiving the vector3.

1 Like

nice :heart: , haven’t seen overseers for a long time, I remember being obsessed with them

For the part representation, how would I make it move to where the replicated NPC is? Do I send the pathfinding waypoints to the server and use the speed-distance-time formula to get the time and update it’s position to the next waypoint?

But my conclusion to what is causing the bug contradicts this: Because all clients are sending data, it might screw with the server’s predictions

TD games manage to get away with this probably because they have set paths and a custom scheduler to predict things easily

Yes TD games often can get away with a lot of the issues because they have predetermined paths and stuff, same with RTS but on a more open scale.

part representation would be easy since the client would only need to reference the actual part position, but keep pathfinding on the client, its way smoother and looks way better, as well more optimized for the server, whoops misunderstood the question. yea actually basically.

But my conclusion to what is causing the bug contradicts this: Because all clients are sending data, it might screw with the server’s predictions

This might be a shot in the dark but why not try getting all the client data, adding them together and then dividing it by the amount of client data so you can get an average and use that instead?

interesting, will try

I’m guessing I’ll put them in a single table, wait like 0.5 seconds and then finally calculate and update the position

1 Like

I think I may have fixed it, I’m gonna wait for my play testers to give some results.

I managed to minimize the “ghost” zombies since you said there’s no way to truly make them in sync for each client by adding a cooldown to the pathfinding function, about 2 seconds; This allows the zombie to actually find a viable path which may also be in sync with other players.

To further make the zombies in sync for each player, if a zombie is very close (20 studs), the server will automatically predict (more like assume) that the zombie already reached their destination through the speed-distance-time formula and update their server position accordingly.

The chance of ghost zombies are reduced and I observed that the zombies will gradually be in sync with other players overtime

The only solution to this may be to just make the game singleplayer if you really want optimized hordes of zombies, otherwise you have to be haunted by the ghost zombies :ghost:

1 Like

that sounds amazing to hear, glad to hear u fixed it

1 Like