Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I reduce lag from remote events?

Asked by
NecoBoss 194
6 years ago
Edited 6 years ago

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.

0
Don't know, this probably happens with all guns. I had it too. https://scriptinghelpers.org/questions/46376/how-can-i-make-this-raycasting-gun-less-laggy hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
Ad

Answer this question