BufferModule | A system built to help combat input latency on Roblox!

Header Image

About

BufferModule is a system built to help combat input latency when using physics on Roblox. This system is built using the principles described by TheNexusAvenger in this article on his website.

Why is this Important?

A delay between a player firing a weapon or projectile can seriously the user experience in situations where the connection isn’t optimal (which is surprisingly often!). Lag creates a disconnect between the player’s input and what they see happen on screen.

Furthermore, lag can cause players to miss their targets unfairly when firing weapons. Players should not have to compensate for their ping when playing a game.

Why use this implementation?

  1. Support for multiple items inside of the Buffer
  2. Security features that help protect against abuse of the system

How does this work?

This module creates a Folder that stores all items added to the Buffer via the server, such as projectiles. When an item is added to the buffer it will have its NetworkOwnership assigned to whichever player is given ownership over the buffer (e.g the player who is holding a weapon).

Buffered items are held suspended far away from the play area. When the client needs to create a new projectile, such as when the player activates a weapon, instead of creating a new Instance we instead pull an existing one from the Buffer. Since the Instance already exists and we have NetworkOwnership over it, we can instantly start controlling the physics of the item.

On GitHub, the repository contains an example place with some tools you can test for yourself. Attached below are videos that demonstrate the difference in input latency with 400ms ping. Pay close attention to the firing sounds and clicking indicator in the bottom right.

Before Implementation

After Implementation

The first video sees the player suffer from serious input lag due to their high ping. However, in the second video, this is completely solved. Great!

The system has uses other than weapons too, such as this tool that spawns blocks. The black outline represents before the request to place a block has been received by the server. For this example, 10 blocks are held in the buffer:

Block Spawner Example

Caveats

As nice as the system sounds, it does come with some clear caveats that may influence if you decide to use this system over something else:

  • This method is not supported natively by the Roblox Engine. This comes with some weird downsides, such as how buffered items need to be stored as descendants of the Workspace, or how buffered items cannot be Anchored until they are removed from the buffer.
  • The client has control over the physics of items in the buffer. This comes with the usual security concerns of giving the client NetworkOwnership over parts.

Installation & documentation

Installation and documentation are both handled through GitHub.
Installation GuideView documentationGitHub Repository

Final Note

Questions, suggestions or bugs? You can open an issue on the GitHub repo - or alternatively, let me know in this thread or message me privately. Thanks! :heart:

99 Likes

I always wanted to ask, I read the source code multiple times already too.

How does it work?

1 Like

I recommend viewing the resource the dev kindly provided and also the documentation, please always ensure to fully read everything.

I’ve made some small changes to the module! Functionality still remains the same.

The latest version of the module no longer holds projectiles in memory for any longer than necessary. Also, it is now being distributed through GitHub instead of the Roblox library.

Along with the script changes, the example superball provided with the module also has had some changes to address a problem and improve clarity. (@RuizuKun_Dev)

2 Likes

I’ll try it out and let you know if it works. Thank you for taking the time to explain it to me.

There’s no latency to mask from the perspective of other clients, only the latency between the client firing the ball’s input and the ball actually being thrown. So yes! :slight_smile:

1 Like

This module won’t offset this, unfortunately. (latency sucks!) However, it will ensure that the projectile will be in the same position across all clients and you may find that to be better than your current implementation.

If you require users to be able to move out of the way to dodge projectiles fired by other players, then changing your system to let the server handle the projectile physics and hit detection will at least further reduce the latency for the player being attacked. But of course, this comes with latency and won’t be suitable for many use cases.

Alternatively, depending on your use case you can try and design around the latency too. For example, a direct blocking or dodging system could help by waiting to see if the user counters the attack before registering damage. Also, particles and other visual effects can help to make impacts clearer and minimize confusion too.

2 Likes

Yup. In the GIF below, the server has network ownership over the projectile the entire time.

GIF

RobloxStudioBeta_sCVKwngOi0

Despite the conditions, when the projectile is initially fired you can see a small delay before the projectile actually begins to move. This is an issue with the Roblox engine and isn’t something that you can easily solve.

I think there’s some confusion here! The client does control the physics of the projectile the entire time, with the server creating it before it needs to be fired and assigning ownership. I’ve further modified the wording of the original post to hopefully help make things a little clearer, but it’s not an easy topic to explain.

Looks great! I’ll use this later on.

1 Like

It looks like that is all this module does. Are you sure a whole module needed to be created for a single line of code?

1 Like

If this module was simply just changing the network ownership of things, I wouldn’t have created it.

The physics of the projectile is still handled by the client with this system.

I’m in the process of rewriting the module right now and will hopefully have things explained better very soon, as this approach to handling things seems fairly uncommon (apart from the original implementation from TheNexusAvenger) :slight_smile:

This is the case yes. Looking back, I realize this is what you initially asked and I misinterpreted your question :man_facepalming:. Sorry!

Making things more efficient, adding more functionality, better security, and some other things!

v2.0.1 is released! :tada:

The module has been rewritten from scratch! Please note that code written for versions below v2 is NOT compatible!

  • Better optimisation (will use less memory).
  • Security improvements.
  • Support for more than one item in a buffer at the same time!
  • Added the source code to the repository (Issue #1 on GitHub).
  • Added a documentation site on GitHub with more in-depth information
  • Added a new example place with new tools and more!

Please continue to feedback, it’s been super useful so far. Thanks!

8 Likes

can you give an example script of how to use it or provide a working test place as yours doesnt work anymore

Seems to be working for me, make sure you grabbed the latest version from the GitHub repository

Can this be used for Soccer ball latency?

@Fizzyhex I’m also curious if this would work with a soccer ball that doesn’t really “belong” to any player. It’s just a ball in the workspace where physics are applied when the game sense it is touched by a player.

Would this help? If so how would I implement it for the problem?

To help with the latency between different players kicking the ball? Not for that scenario.

1 Like


Does creating a lots of projectiles on the server increase lag spikes? I’m curious