This post was last updated on 2/1/2026.
Better optimizations may be found in the future. If you have any in mind, please tell me, I’ll attempt to update this post (no guarantee).
Performance tips (network bandwidth, client framerate, etc.) for custom NPC replication
Heya! This serves as a compilation of tips and tricks I’ve learned from my research on custom NPC replication. Originally a comment on a thread, but I decided to post and extend it.
For context, what I refer to as “custom NPC replication” is:
- Pathfind + send position data for NPCs on server (rather than placing actual models and humanoids and letting Roblox handle the replication)
- Render position data for NPCs on client
Why would one develop their own replication system?
Now without further ado, let’s begin.
Limiting how often you send data + client interpolation
The rule of thumb is you should only send necessary data, when it is necessary.
Realistically, you don’t need to (and shouldn’t) send data every frame. A common rate is sending data every 1/10th of a second, or basically 6 :FireAllClients() every 1 second. Do note that there is no one-size-fits-all update rate, test out different values and see what fits with your game’s needs.
Assuming you’re using .Heartbeat, limiting your data could look like this:
local counter = 0
RNS.Heartbeat:Connect(function()
if counter < 10 then
counter += 1
return
else
counter = 0
end
-- send position data to clients
end)
Furthermore, you should only send out position data (server) and render models over that position data (client) of NPCs that have changed positions. This should save up network bandwidth for other replicated objects (parts, animations, etc.)
Now once the client receives this data, you can then interpolate each NPC towards each position. It can look like this:
local npcHRP: CFrame = ...
local positionData: CFrame = ...
npcHRP.CFrame:Lerp(positionData, .05)
I also recommend changing the value of the interpolation through deltaTime (assuming you’re rendering with .RenderStepped) to account for FPS spikes or framerates beyond 60 FPS.
local deltaTimeConverted = deltaTime / (1 / 60)
npcHRP.CFrame:Lerp(positionData, .05 * deltaTimeConverted)
Compressing your data before sending
We can further improve network bandwidth by decreasing (compressing) the amount of bytes our data holds. Same rule of thumb as above applies here; only send what is necessary. Now when it comes to networking, you need to think in terms of bits and bytes:
- A bit is either 0 or 1
- A byte has 8 bits
- A kilobyte has 1000 bytes or 8000 bits
For a general guideline for data types and their equivalent bytes (and networking in general), read this post by @PysephDEV, very helpful. The numbers of bytes that I will mention will mostly come from the post, but anyways…
Side note,
The resource has some outdated information (e.g. string byte size), you can look into this .luau file on Github, also made by @PysephDEV.
First tip, always use arrays over dictionaries. Dictionary (non-integer) indexes just cost you extra bytes and aren’t necessary. Here’s an example:
-- instead of ~28 bytes
local data = {
-- "CFrame" -> ~8 bytes
-- CFrame.new() * CFrame.Angles() -> ~20 bytes
CFrame = CFrame.new() * CFrame.Angles()
}
-- reduce to ~20 bytes
local data = {
-- CFrame.new() * CFrame.Angles() -> ~20 bytes
CFrame.new() * CFrame.Angles()
}
Second tip, if you’re sending out CFrame’s, you can compress its position and rotation components. There are many ways to do this, but here are some common ones:
As a reminder:
- CFrame takes up ~20 bytes
- Vector3 uses 32-bit (4-byte) floats per coordinate, taking up a total of ~12 bytes.
- Vector3int16 uses 16-bit (2-byte) integers per coordinate, taking up a total of ~6 bytes. It’s range is
[-32768, 32767] - Numbers use 64-bit (8-byte) floats, taking up ~8 bytes (regardless of whether its 1, 1.000001, or 100000)
The first way is to convert your CFrame into two Vector3int16.new(), it can look like this:
Side note,
If you’re working with radians which you most likely are, keep in mind that Vector3int16 uses integers only.
To make sure your radians (which have a range of
[-3.14, 3.14]or[-math.pi, math.pi]) stay intact, I recommend multiplying them by 10 as you insert them in aVector3int16.new()and dividing by 10 (or multiplying by .1) when converting them back into CFrames. I’ll be doing this method below.
local cframe = ... -- ~20 bytes
local rotationX, rotationY, rotationZ = cframe:ToOrientation()
-- a total of 12 bytes, drastic improvement from 20 bytes!
local position = Vector3int16.new(cframe.X, cframe.Y, cframe.Z) -- ~6 bytes
local rotation = Vector3int16.new(rotationX * 10, rotationY * 10, rotationZ * 10) -- ~6 bytes
-- converting position and rotation back into a cframe can look like this!
local newCFrame = CFrame.new(
position.X,
position.Y,
position.Z
) * CFrame.Angles(
rotation.X / 10,
rotation.Y / 10,
rotation.Z / 10
)
The second way is to further compress your position and rotation via Vector2int16.new() and numbers.
For position, if you only have one height (Vector3 Y) per coordinate, you can just send out a Vector2int16.new() instead like so:
Side note,
For those wondering how the client could get the Y coordinate, you can look into height maps like in this post by @Atrazine. Big credits to this post, genuinely super helpful.
-- old
local position = Vector3int16.new(cframe.X, cframe.Y, cframe.Z) -- ~6 bytes
-- new, let the client handle the Y (e.g. through height maps)
local position = Vector2int16.new(cframe.X, cframe.Z) -- ~4 bytes
For rotation, usually it’s safe to assume that only the Y axis (e.g. turning left to right) is changing, so we can just send the Y axis.
Now keep in mind that numbers are 64-bit (8-byte) floats, which is why we should compress the rotation even further through the buffer library. In the example below, I compress rotation into a 16-bit (2-byte) integer:
-- old
local rotation = Vector3int16.new(rotationX * 10, rotationY * 10, rotationZ * 10) -- ~6 bytes
-- normal numbers
local rotation = rotationY * 10 -- ~8 bytes
-- compressed numbers through buffer library
local rotationBuffer = buffer.create(2) -- a size of 2 bytes for 16-bit number
buffer.writei16(rotationBuffer, 0, rotationY) -- ~2 bytes
-- getting back the number is as easy as
local receivedRotation = buffer.readi16(rotationBuffer, 0)
Batch CFraming for rendering NPCs
Even with good network bandwidth, your clients can still lag if there are too many units being CFrame’d every frame (render step.)
A method to improve client performance is :BulkMoveTo() which allows you to set the CFrame of parts in a single batch. This is more performant than individually setting each NPC’s CFrame through a loop because the function runs directly on C++ and optimizes other things behind the scenes. To quote its documentation,
This function moves a table of BaseParts to a table of CFrames without necessarily firing the default property Changed events. This provides a very fast way to move large numbers of parts, as you don’t have to pay the cost of separate property sets for each individual part.
By default, the Changed event of each part fires for Position, Orientation, and CFrame. However, if you specify FireCFrameChanged as the third argument, only the Changed event for the CFrame property will fire.
https://create.roblox.com/docs/reference/engine/classes/WorldRoot#BulkMoveTo
Here’s an example of how you could implement it into your code:
-- instead of rendering npcs like this
for i,v in npcList do
local npcPart = ...
local npcCFrame = ...
npcPart.CFrame = npcCFrame
end
-- you can use this instead
workspace:BulkMoveTo({npcPart1, npcPart2, ...}, {npcCFrame1, npcCFrame2, ...}, Enum.BulkMoveMode.FireCFrameChanged)
Just a reminder that Enum.BulkMoveMode.FireCFrameChanged will reap the most performance benefits (as explained in the documentation above), so always use it for the third parameter.
Implementing render throttling for large amounts of NPCs
To repeat what was said above, sometimes the network bandwidth isn’t the limiting factor, but the rendering itself. When you are CFraming NPCs in the four digits (1000+), you are may be experiencing unstable framerates, especially on lower-end devices.
Instead of rendering all NPCs per frame (render step,) you can divide it into smaller batches and alternate between them. To give an example:
- Rendering 1000 units in a single frame
- Rendering 500 units for a frame, rendering the other 500 units for the next -----> 50% workload reduction per frame
- Rendering 250 units for a frame, rendering the next 250 units for the next, and so on and so forth -----> 75% workload reduction per frame
Do keep in mind that because you aren’t rendering every NPC at every frame, NPC movement can look choppy (not by much, but it can still be noticeable). This choppiness can be decreased by how you will divide your batches, but not completely removed. This should only be a last resort.
Here’s an example on how you could do it (assuming you use:BulkMoveTo(), but you can adapt it to your own system):
local npcRenderThrottle = 300
local queueData = {}
--[[
this example assums your data and queueData are arrays
and that the values of the arrays are also arrays where the actual data is stored
e.g. data = {
{npcPart1, cframe1}
}
]]
RNS.RenderStepped:Connect(function()
local npcList = {}
local cframeList = {}
local isQueueAvailable = #queueData > 0
-- data refers to the actual position data you get normally
for i,v in (isQueueAvailable and queueData or data) do -- uses queueData when available, otherwise, uses data
local npc = ...
local cframe = ...
if isQueueAvailable then -- if there is queue however.. focus on getting rid of that first
table.remove(queueData, table.find(queueData, v))
table.insert(npcList, npc)
table.insert(cframeList, cframe)
else
if i > npcRenderThrottle then -- above throttle? add to queue
table.insert(queueData, ...)
else -- otherwise, just add npcList and cframeList
table.insert(npcList, npc)
table.insert(cframeList, cframe)
end
end
end
workspace:BulkMoveTo(npcList, cframeList, Enum.BulkMoveMode.FireCFrameChanged)
end)
Pathfinding via flowfields (flowfield pathfinding)
This isn’t specific for custom NPC replication, but for games with a ton of NPCs in general.
Roblox pathfinding, at least from what I understand, creates a NavMesh and uses A* to traverse through. It’s very good for generating accurate(ish) waypoints in dynamic environments. However, it is computationally expensive.
In comparison, flowfield pathfinding runs on the principle of “calculate a path once, reuse for all NPCs.” This allows for the pathfinding of hordes of NPCs with little performance cost.
In simple terms, it creates a grid and calculates a direction for each cell, where all cells eventually flow into the target position.
This means that NPCs can pathfind using the same flowfield from any position. And you only need to recalculate whenever the target(s) have changed positions or the environment has changed.
Side note,
If you’re looking for a module to generate performant flowfields (with chunk pruning optimizations), you can try FastFlow by @bob_factory, very pleasant to use.
It pathfinds on a 2D grid by default, but if you’re looking on how to implement flowfields with 3D grids / maps, you can read this post by @happya_x.
Honorable mentions
Multithreading / parallel luau
You can look into multithreading / parallel luau via Actors, but there’s honestly not much you can do with it besides split up calculations on the server (you can’t render in parallel unfortunately, setting CFrames is not parallel safe.) Here are a few notes on it:
- You’re recommended to use 32-64 Actors; too little and you won’t see much effect, too much and it’ll be hard for Roblox to distribute all the workload
- Avoid long and time-consuming computations for Actors, more detail can be found on this part of the documentation
- Further best practices can be found here
Important side note,
At the time of writing this, the client has been capped to 3 total parallel threads due to design limitations. I believe it’s currently being worked on, but unfortunately, there is no apparent timeline on when it will be fixed.
Native code generation
You can also look into applying native code generation via @native on your server calculations (e.g. compression with buffer library), theoretically speaking you’re trading CPU performance for memory. There’s no guarantee for better performance though, so use the ScriptProfiler to see if it makes a difference. Further best practices can be found here.
Networking libraries
And yeah, I should address networking libraries. If you’re interested in decreasing your network bandwidth even further, networking libraries aim to reduce the overhead of RemoteEvents (~9 bytes per RemoteEvent fired). This reduction is a big difference in overall network bandwidth, and it really shows when you go past 1000+ NPCs. There are many networking libraries released to DevForum, so do your research.
From what I understand, they mostly work by batching multiple RemoteEvents into one RemoteEvent + compressing the data passed through (e.g. with buffers.) For more details, this post by @Content_Corrupted019 has a very detailed explanation on how it works.
External resources
Lastly, I recommend reading these posts as well, they were extremely helpful for my research:
