Can someone explain to me ways to fix game latency?

I’m a new scripter that’s hoping to make my first game on ROBLOX. However, a huge problem in my game is the lag in the game. I have read this article about lag however I still do not understand it.

My Problem
I have a sword tool and when you click, it fires a remote and that remote plays the animations/effects and enables some values for the damage server script to deal damage. The damage server script checks the player’s stats and if a certain value is true, damage can be dealt and that’s how I’m doing it. The damage server script doesn’t have any lag since I’m looping it however the swinging is the problem.

How I tried to deal with it
I have read other posts about how I need to “split the work between the client and the server” however I don’t understand how to “split the work.” At first, I figured that the equipping and the unequip animation could just be on a local script so I did that. The problem is with the swing animation.

When I try to make something, I always keep exploiters in mind. If I don’t add a check such as a value or something, the animation could just be played over and over again. I’m not sure if that’s good but when I try to add a check in local script, “if value == true then” there is delay between the mouse click and the animation playing. It doesn’t feel smooth. With that much delay, I might as well just put everything on a server script and run that. The delay is basically the same. Also, when I swing the sword, a trail is enabled and the damage value that the server checks is enabled allowing the player to damage another player and it turns off after the animation stops playing. If I’m trying to “split the work”, I’m thinking that I need to put everything visual on the local script and everything that is important on the server script. However, how do I activate the sword trail so everyone in the game can see it? I’m honestly confused.

What I’m trying to achieve
I’m trying to make a sword tool that swings without delay and works perfectly fine. It also shows every player in the game the sword trails and also have a working cooldown. (I’m not sure if I’m right but I think cooldowns do not work on localscripts since it can’t set values that replicate to server, and I don’t want to have a remote just to do that since exploiters could just loop fire that remote and disable cooldown.)

There aren’t any videos on youtube teaching you how to fix this issue either. Can someone please explain to me how I can achieve my goal?


Alright, your idea of ‘splitting the work’ is pretty much correct.

Lag is something that you circumvent by making it seem like there is no delay to the server. However, this delay is strictly determined by how you have made your game. If you game is inefficient then it will exasperate this issue.

To not have your server lag you incoroporate the practice of ‘splitting the work’. Do not have perpetual loops in your server, is one big factor to lag - I would just like to add.

Though before I ramble, could you please post a gif of some sort showing the issue at hand? This is because typically lag shouldn’t be so jarring. Atleast, your pring should be below 100ms.

1 Like
My ping is around 200-300ms and the lag isn’t so bad but theres like a 0.05-0.1 second delay
It wasn’t so bad like before, maybe my wifi is better today? I’m not sure.

Edit: I think it’s faster after I changed the remote function to a remote event.
Here’s the tool with 0.5 millisecond lag inside studio. ( I tried to show when I clicked, when you see the kind of black square next to the cursor it means that I clicked. As you can see, there is a lot of delay ( ping inside studio says around 1000ms )

also I made it so that only when the blade touches something in the damage script, it performs a magnitude check so it doesn’t loop.

This really just seems like the result of a misplaced “wait()” somewhere in your code, I’d recommend looking back over it and clearing up anything of the sort.

If that is not the issue, to put it simply, it is most likely server lag on the part of studio. If you try it in game if there is a difference? If not, is your ping consistently high and independent of studio/player?

1 Like

I have checked over the script and I don’t seem to find any problems with the wait(), if studio’s lag option is from 0.1 - 0.3, it’s perfectly fine with little to no delay however more than that has a pretty big delay. If I lower the wait() values then it would be way too fast.

Does checking a lot of values with “if value1 == true and value2 == true and value3 == true and value4 == true then” slow things down? If so, that might be the problem.

I’m trying to find a solution for people who have bad internet ( more than 600 ping )
or do I just keep it like this?
( if I have around 300 ping it also has a little delay )

Would it affect my game if extremely laggy players can’t really play?

Well, that is unusual. The game I am working on routes everything through the server, and the most abrupt delay I see is 100 ms. This really must be due to the way you have made it, as servers shouldn’t take 1 whole second to computer whether you can do something.

There shouldn’t be any detriment to using a couple if statements, also. I have to do some pretty stringent computations and my game (with a load of other stuff running) still has latency that isn’t noticeable.

One thing you can do is press f9 and check your average ping (in an server run by roblox), if it is massive, then this is something to do with the server (And you may have a very long road ahead ;-;). If it isn’t, then this is something that you can fix.

This is an example of some simple combat that I route through the server. The server makes sure I can do the move, then - here is how I distribute work - fires ALL clients to do the effect (in this case that weird air spike thing). The server only does the hitbox, everything else is just sent to the client. (There is a module that does something like this if I recall. My method is probably a little crude, so please see if you can find it in the resource area.)

This is because tweening is damn resource heavy.

You should do some checks to see how long it takes your server to process when it begins the move. Ie after it has checked everything, and it begins initiating it. It should really not take that long, and with how multiplayer games work today, if you are laggy then you won’t have a nice experience at all anyway.

If your server is indeed fine, and you want no latency you can, instead, have the client do the move immediately, and then have the server check if it can, and if it can give it a hitbox. Though this has its flaws, many big. Another is to add a little effect just after you inititiate the attack, so that it reduces focus on the move and makes it seem instant. This is what the guide was saying (probably I only skimped through it).

But this would all be pointless if your server is heavily strained from something. Make sure it isn’t, otherwise you will have a very big issue at hand.

I would also like to add that hitboxes can be very resource stringent if not done right. There is a well made raycasting method in the resource area that is suitable to sword mechanics. You should try to implement it if you can.

Thank you very much for the ideas!
I’ll see if I can fix it.
I’m pretty sure that the lag isn’t caused by the server as I’m in a game with pretty much only a base plate and my average ping is around 260 - 300.
I’ll see if I can find those posts in resources!

I have another question though, how do I use fireallclient like that?