So I've created a laser gun from scratch, and it works perfectly, I'm pretty proud of it tbh but it lags on the actual game. I'm using a simple FireServer() when the tool is activated to let the server do the rest of the work on a server script inside the tool as well, but in game it's pretty laggy. When I play it, I have about .2 - .4 seconds of lag between when I click and when the gun fires. I'm using body velocity to move the projectile and the projectile is also fairly laggy.
But then I went to other games to see if it was just my internet, but games like prison break has no gun lag at all. I've heard varying responses that you just have to deal with the lag so I'm confused how some games pull it off.
Any help would be appreciated.
Edit: Also I've already consulted the wiki article on fighting lag but it gave no solutions and just things to cover the lag up. The only solution I can see is to simultaneously fire a projectile within the client, and another one in the server. That way both players only see one projectile, and the player firing doesn't see it lag.
When firing the weapon, make that client-side, not server-side. Then, if the projectile hits a target (I'd do this client-side, to make it feel more responsive), send a message to the server to do something.
You may have to simulate the projectile client-side with Raycasts and CFrames. This would make sure that the server wouldn't be doing so much work and reduce the lag.
Also why is a 'lazar' gun being moved with BodyMovers(BodyVelocity)? Shouldn't you just raycast it instead?
(Example of a formula for bullet drop simulation if needed. It uses client-side raycasting)
bullet.downVelocity = (bullet.downVelocity * bullet.drag) + 0.002/bullet.speed bullet.forward = bullet.forward * bullet.drag bullet.drop = bullet.drop - bullet.downVelocity local newPos = bullet.pos * CFrame.new(0,0,bullet.forward) + Vector3.new(0,bullet.drop,0) local oldPos = bullet.pos local distance = (newPos.p - oldPos.p).magnitude local r = Ray.new(oldPos.p,(newPos.p - oldPos.p).unit * distance) bullet.pos = newPos