Sorry if this is the wrong category, but i’ve been interested on rendering NPCs locally and not in the server recently, as some people say it’s better for the server performance, however, i’m not sure how people does it with moving NPCs and such? does anyone have some documentation that could guide me? it’d be very appreciated
I currently have a zombie that follows the player
If you would like an NPC that follows players (mobs I assume) I recommend referencing the following post that is similar to yours: Mob in front of you
No no no, i already have that, i’ve read on this same forums that rendering NPCs locally is less load for the server, however i’m not sure how should i start working on that and such, that’s why i’m asking if someone knows about some documentation or anything that i should read to get the hang of it.
Parent the NPC to Workspace.CurrentCamera which will show them to only the player that the script is executed in.
This question hurts my brain, not because I don’t like it but because you know, complexity, but I’m trying to make some predictions from what I know so far.
If you’re going for performance when it comes to multiple zombies, you’ll need to do some extra optimizations before you try this. Too many server-sided zombies have an impact on physics, but at the same time too many client-sided zombies will have more of an impact on local performance than server physics.
I think that you should create the NPCs serverside, but if you want to make it locally, I suggest using RemoteEvents. See the following article for more information: Custom Events and Callbacks | Documentation - Roblox Creator Hub
He wants to Render them locally, not manipulate them locally.
You don’t need a remote to render things locally, remotes have a completely different use than that. Let’s please not turn this into a controversial fight.
Thank you for pointing out the flaw in my suggestion. It was really helpful.
I have no experience in rendering NPC’s but I’m gonna try and answer. I won’t be supplying any code as my reply is a breakdown of how I would do this.
As you’re rendering the NPC locally, the “zombie” on the server is going to be a single part. The actual zombie model will be 100% client side and won’t contain a Humanoid.
I’ll start talking about the server-side of things
You’ll want to start with a folder in your workspace named “Zombies”. Every time you spawn a zombie you’ll create a part the size of a normal HumanoidRootPart(2,2,1) and parent it to the Zombies folder.
The server will be responsible for mimicking humanoid behaviour and moving towards the closest player.
I would use BodyVelocity to keep the Zombie moving at a constant speed of 16 studs per second (default humanoid walkspeed) and move it towards the player and BodyGyro to rotate the Zombie to face the player.
Note: You would make the Y axis for the BodyVelocity and BodyGyro the same as the Y axis of the Zombie otherwise the Zombie will float up or down depending on if the player is high or low (or possibly jumping).
That’s really it for the server- you most likely already have code for damaging a player if you have a player-chasing zombie so it’ll be easy to convert.
Onto the client-side of things!
The folder we made at the start? We need that now. You’ll use ChildAdded to run a function every time a Zombie is added to the folder. You need an if statement to check if the object that is added to the folder is a part using :IsA(“BasePart”) so that your code won’t error.
Next you’ll want to create a function that generates the look of the zombie - I don’t believe you can use Roblox Shirts & Pants without using a Humanoid so you’ll need to create custom zombie clothing out of parts or decals/textures.
After the :IsA(“BasePart”) code, you’ll run the function I mentioned above and return the zombie model. You’ll weld the zombie model to the Zombie Part you got from the ChildAdded function.
So now we have a Zombie chasing the Player but on the server it’s just a single part.
To play animations on a non-humanoid model you need to insert an AnimationController which also means you’ll need to create your own Animation Handler script so you can run an Idle, Walk, Chase and Attack animation for your zombie.