What causes projectile lag?

My game sometimes experiences major projectile lag and input lag. I tried using the microprofiler to determine the cause, but everything looks perfectly fine on the profiler. What could be the causes?

1 Like

There are a number of things that could be causing it. For example you might just have too many projectiles at once, causing the lag (although that would be noticeable on the profiler). Or you might not be setting network ownership correctly.

Do you have a place where the lag is occuring?

2 Likes

How would I set set network ownership “correctly”? Does setting the network owner to nil for every projectile cause issues? If so, then that’s my issue

1 Like

Setting the projectiles to nil just lets the server take control of ownership, so you will end up with nice and stuttery projectiles

2 Likes

This doesn’t answer your question, but here’s a post for you to check out that’s related: Making a combat game with ranged weapons? FastCast may be the module for you!

You might find it useful :slight_smile:

2 Likes

If you want this to look smooth, you should fire a RemoteEvent before creating the actually projectile locally.
First, set up an event that responds to a RemoteEvent with :OnClientEvent(), code in here must use the same code you use to create the projectile.

Next, have a script in ServerScriptService with a function that responds to event you fired to the server.
Have the function contain code that does :FireAllClients() and creates the exact same projectile. Note that you will have to carry through information when firing the RemoteEvent so that the projectile you fired will be the exact same for other players

Example values you would want to carry through: Position, direction, Player name, ETC.

Now, to prevent you, the original creator of the projectile from receiving a duplicate thanks to the function we made that responds to OnClientEvent, have it check for the player who originally fired the first event.
Add this condition to the function in the same script that responds to th event and creates the projectile.

–
What this all does is create a projectile based on the information the client that originally fired a projectile gave and does this for all other clients.
The projectile will always be traveling just as smooth as their own game is running.

If you want me to explain something in greater detail, do tell.

3 Likes

But depending on the person’s lag, won’t the projectile move slower for them?

2 Likes

I haven’t really experienced with big player servers and different connection types,
but it shouldn’t cause problems if you have the actual damage be registered from the client and fired to the server.

Also note, you can’t have an object move at 60fps or at a constant speed if the client is having serious connection issues. As far as I know, this is nearly impossible to avoid.

1 Like

You would normally only do this when the effect is purely visual, and you don’t care if all players see events play out differently. I don’t just mean that timing will be different, I mean that something like a bouncing ball could go in completely different directions on different clients. That may be OK for a visual effect, but not for something like, say, a grenade in PVP. For projectiles that use server-side, server-authoritative collision detection, you want them to be owned by the server (network owner nil), otherwise your scenario ranges from one player having an advantage, to (worst case) a player tampering with their client’s simulation being able to exploit your game.

Server-owned does not imply stuttery. Server-simulated things are still interpolated on each client to smooth out the motion. Things are usually stuttery when things are moved on the server via CFrame or Position setting directly, which is like mini-teleports at 20 fps. Server-owned simulated parts can also slow down if the server is over-burdened simulating too many things at once, at which point projectiles might appear to be moving in slow motion or defying gravity.

13 Likes