Gun Sounds Glitches

Hi,
I used remote events to make gun sounds play in the server, but it seems laggy.( sometimes when gun are automatic, it plays a same sound per second)

Module:

function PlayAudio(cmd, audio)
	if cmd == "Play" then
		if audio then
			if audio.Looped then
				if not audio.IsPlaying then
					audio:Play()
				end
			else
				audio:Play()
			end
		end
	elseif cmd == "Stop" then
		if audio then
			if audio.IsPlaying then
				audio.Playing = false
				audio:Stop()
			else
				audio.Playing = false
				audio:Stop()
			end
		end
	end
end

return PlayAudio

Is it a glitch or lag you’re experiencing? They are two very different concepts. In general though, your system seems fine. The only bottleneck is network response time as a result of using remotes, but it’s not something you can avoid.

I recommend that you change your networking model. When a client requests to play a sound, have the server validate the request rather than then being authoritative of sound playback as per your current system. When the request passes, have the server fire the remote again back to other clients and let them play the sound.

@mistr88 That sound system already released. That is irrelevant to this problem, that is only a change in relation to character sounds.

3 Likes

How do I do it???

This is very misleading advice

(1) Lua does not require parantheses around conditional expressions or in if statements, except to indicate higher precedence.

(2) There is no reason why that would make it play twice. All he is doing is checking if it’s already playing if it’s a looped sound.

(3) Since the PlayAudio function is the only thing returned by the module, and handles no self parameter, it is fair to assume that there is no reason it needs to be called as a method. We don’t see the portion of the code in which OP assigns the module’s function to _G to begin with either. Functions stored in a table don’t always have to be called as a method (with the colon operator). You can read more about methods here or here

It’s important to be wary that you have your facts straight before you try to help people. It sounds like you’re quiet unsure yourself, in which case you should either (1) use appropriate reference material to try answer the question, rather than relying on your own assumptions that you say you are unsure of, or (2) leave the question for somebody more certian to answer.

3 Likes