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.
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