Gun sound lag problem

Currently I’m trying to make a gun and of course it needs to play the gunshot sound. What I did is that everytime they click it FireServer and then on the server it FireAllClient which plays the sound on another local script. The problem is that it still lags, is there any other way to do this?

Gun’s Client Script:

game.ReplicatedStorage.Sound:FireServer(tool.Handle.Gunshot)

Server Script:

game.ReplicatedStorage.Sound.OnServerEvent:Connect(function(plr, sound)
 game.ReplicatedStorage.Sound:FireAllClient(plr, sound)
end)

Sound’s Local Script:

game.ReplicatedStorage.Sound.OnClientEvent(plr, sound)
 sound:Play()
end)
3 Likes

Quick Optimisation

You don’t need to plr value as it fires to all clients.

1 Like

Oh sorry, I just rewrote the code quickly, but would that in any way fix the lag?

Can you define lag, like is it not playing instantly when you click your mouse?

At some points it plays, but then just stop randomly but play again. Like shoot sound plays for 3 seconds but then stops for another few second and repeat.

Have you checked the SoundInstance propertys?

Could you tell me more on what I need to check?

If Loop property is enabled, since you mentioned it was repeating.

No no, I’ll explain more on how the gun works.

Every time you hold click/click it will play the gun sound, but using the script I used the sound just don’t play sometimes.

I’m lost for ideas on this one sorry, however quick recommendation, you should play the sound on the server instead of firing all clients to prevent exploiters spamming the sound event and have some check in place.

I’ve tried playing the sound on server but that lags as well. It works perfectly fine on Studio but when I join an actual server the sound just lags.

I suspect its your gun script possibly using functions that slow down the process. Could you possibly attach how you are triggering the fire server event.

This is probably just from ping. (I assume?)

You could play the sound locally and have it replicate server-sided. (the server could tell all other clients to play the sound, excluding the player firing the gun.)