I am experiencing lag with my gun system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the bullet trails to come out of the barrel instead of a couple of frames later where the barrel was.

  2. What is the issue? Include screenshots / videos if possible!
    There is a very noticeable delay in the gun’s bullet trails. https://streamable.com/u5owi5

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have consulted many forums regarding the gun delay, I have tried applying the checks on the client said as one said and it did not work.

Assuming you’ve already made the bullet trails client-side, try assigning network ownership:

Instance:SetNetworkOwner(Player)

Instance being the bullet trails, and Player being game.Players.LocalPlayer

It would be of great help if you included the code relevant to the functioning of the trails.

1 Like
	local trail = Instance.new("Part",workspace)
	trail.CanCollide = false
	trail.Name = plr.Name.."Bullet"
	trail.Anchored = true
	trail.Transparency = 0.5
	trail.Material = Enum.Material.Neon
	trail.Color = Color3.fromRGB(201, 28, 207)
	trail.CanTouch = false
	trail.Size = Vector3.new(0.1,0.1, (barrel - position).magnitude)
	trail.CFrame = CFrame.new(barrel,position) * CFrame.new(0.1,0.1, -(barrel - position).magnitude/2)

But I am instancing the trail on the server.

That’s the issue, you need to instance the trail on the client and then replicate it to every other client. Create the trail on the client, then fire the server using a remote event, then use the server to FireAllClients().

The server-client delay is what’s causing this stud difference between the barrel and trail.

2 Likes

The bullet is an anchored part, so I can’t assign set network owner, I will try to find a fix for that if you don’t have one.

Then you don’t need to use network ownership. Just draw the bullet locally immediately, and then send the data to replicate for all other players in the game, and have the server manage sanity checks to determine if damage should be dealt.

4 Likes

I tried that but I am still experiencing some lag. As the gun user, there is no lag, but once I tried the two player test and the second player saw the gun barrel like pretty far away.

There’s always going to be some replication delay.

One thing you could do is rather than sending the origin position for the bullet to each client, you could possibly still send their aim direction, but on the other clients you could get the current position of the firing player’s weapon so it appears more accurately, when you go to draw the bullet.

“:SetNetworkOwner” can only be called by the server so “game.Players.LocalPlayer” wouldn’t be defined.

You realize it can be defined on client and sent to the server?